You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's possible to implement empty objects/tuples/arrays having a size of 0, but I personally don't think it's worth the added compiler/language complexity.
It looks like there's already a type of size 0 that add nothing to any structure it's part of.
type Empty = distinct array[0, byte]
It must be based on an 8 bit type so it doesn't alter the layout (e.g. if it's an array[0,int64] it will instead force any adjacent type into 8 byte size and alignment).
However seqs seem to allocate 1 byte for each Empty. Similarly, tuples and objects that only contain tuples are equivalent to empty tuples and objects, all of which have size 1.
It looks like there's already a type of size 0 that add nothing to any structure it's part of.
type Empty = distinct array[0, byte]
The size being reported as 0 is a compiler bug -- in the generated code, arrays with a length <= 0 always have a length of 1.
In any case, there's been discussion about a unit type since this question was originally asked. The unit type will most likely end up becoming the type to use for fields/locals when they should not take up any space nor alter alignment requirements.
Should empty objects be of size
0
? Maybe in some contexts that won't even work.Example
Actual Output
Expected Output
Possible Solution
Additional Information
References
The text was updated successfully, but these errors were encountered: