Summary: Better union initialization syntax
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD

--- Comment #0 from 2011-11-25 17:01:51 PST ---
After using several unions for a while in D, I think the syntax to initialize
fields of unions is not handy enough. An idea from GNU-C:

import std.stdio;
union Foo { int i; double d; };
void main() {
    int x;
    double y;
    Foo u = void;
    auto u1 = cast(Foo)x;
    auto u2 = cast(Foo)y; // Error: e2ir: cannot cast y of type double to type


But I don't like that GNU-C idea, a problem with cast() is that it's not
precise enough, if there are two fields like this, what is a good way to assign
's' or 'u' using a cast()?

union Foo { int s; uint u; };

So I'd like a more explicit syntax.

A solution using named arguments seems good:

union Foo { int s; uint u; };
void bar(Foo f) {}
void main() {

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to