Enumerated Unions (sum types)
Paul Backus
snarwin at gmail.com
Thu Sep 12 12:01:38 UTC 2024
On Thursday, 12 September 2024 at 11:19:07 UTC, Dukc wrote:
> On Thursday, 12 September 2024 at 10:33:35 UTC, Paul Backus
> wrote:
>> On Thursday, 12 September 2024 at 10:24:01 UTC, Dukc wrote:
>>> Yes, if the foreign language will only handle it via a
>>> pointer. But if the ABI is nailed down, the foreign language
>>> can have the sum type on an array or at the stack, and pass
>>> them to D functions by value.
>>
>> Even for that, all the foreign language has to know is the
>> size and the alignment. It doesn't have to know how the data
>> is arranged internally.
>
> But to know the size of the sum type, the existence, size and
> alignment of the tag field has to be known. That's why I'd
> prefer it to be specified.
The sum type will have a `.sizeof` property that gives its total
size, with the tag field included.
When the DIP says "the size of the tag field is unspecified,"
what that means is that it's unspecified is how much of the
"extra" space is actually used for the tag field, and how much of
it is padding.
More information about the dip.ideas
mailing list