Union redux

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 2 16:07:32 PDT 2015


On 6/2/15 6:50 PM, Andrei Alexandrescu 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

It's actually unnecessarily redundant. In all cases, you can simply move 
the "valid" one to the first member. Initing the first member is the 
right call.

-Steve


More information about the Digitalmars-d mailing list