Union redux

Manu via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 2 18:20:43 PDT 2015


On 3 June 2015 at 08:50, Andrei Alexandrescu via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On 6/2/15 1:48 AM, Manu via Digitalmars-d wrote:
>>
>> On 2 June 2015 at 05:00, deadalnix via Digitalmars-d
>> <digitalmars-d at puremagic.com> wrote:
>>>
>>> After discussion at DConf, it ends up that union have some lack of
>>> specification, and some nonsensical behavior right now. Here are some
>>> points
>>> discussed and possible solutions :
>>>
>>> 1/ .init for unions is not defined. I propose to define it as the .init
>>> of
>>> the first field + padding with 0s if the union is larger than its first
>>> member. It seems to be what is generated right now.
>>
>>
>> Isn't it the case that some of the members of a union need to be
>> declared with init =void, such that only one version of the union
>> provides the init values?
>> At that point, isn't the state of init clearly defined by the members
>> that aren't =void?
>
>
> That could be done, but strikes me as too clever for its own good. -- Andrei

Right. See, I thought that's just how it already was ;)
I recall writing some union code and having compile errors, and being
required to resolve it by setting =void to all the members in
conflict, effectively making the initialisation of the union explicit.


More information about the Digitalmars-d mailing list