Can we drop static struct initializers?
Steven Schveighoffer
schveiguy at yahoo.com
Tue Dec 29 07:37:03 PST 2009
On Fri, 20 Nov 2009 00:48:28 -0500, Don <nospam at nospam.com> 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).
Brought up in another thread, a good use of static initializers for
structs: arrays of POD literals.
For example:
struct RGB
{
ubyte red, green, blue;
}
RGB[256] PALETTE = [
{0x00, 0x00, 0x00},
{0x01, 0x01, 0x01},
...
];
can you do something like this without static initializers? My
recollection is that this is the only way to have a struct array literal.
-Steve
More information about the Digitalmars-d
mailing list