Can we drop static struct initializers?
Don
nospam at nospam.com
Fri Nov 20 01:47:30 PST 2009
Walter Bright wrote:
> Don wrote:
>> Now that we have struct literals, the old C-style struct initializers
>> don't seem to be necessary.
>> The variations with named initializers are not really implemented --
>> the example in the spec doesn't work, and most uses of them cause
>> compiler segfaults or wrong code generation. EG...
>>
>> struct Move{
>> int D;
>> }
>> enum Move genMove = { D:4 };
>> immutable Move b = genMove;
>>
>> It's not difficult to fix these compiler problems, but I'm just not
>> sure if it's worth implementing. Maybe they should just be dropped?
>> (The { field: value } style anyway).
>>
>>
>
> Funny, I've been thinking the same thing. Those initializers are pretty
> much obsolete, the only thing left is the field name thing. To keep the
> field name thing with the newer struct literals would require named
> function parameters as well, something doable but I'm not ready to do
> all the work to implement that yet.
>
> Or just drop the field name thing, as you suggest.
Dropping the whole lot would make it easier to identify delegate
literals. I think the code below is quite wierd.
struct A { int x; }
alias void delegate () B;
void bar1(A a) {}
void bar2(B b) {}
void main()
{
A a = { };
B b = { };
bar1(a); // ok
bar2(b); // ok
bar1( {} ); // fails. And you can't even do: bar1( cast(A){} );
bar2( {} ); // ok
}
I suspect that there are all kinds of odd corner cases involving these
guys, which haven't been explored.
More information about the Digitalmars-d
mailing list