www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7058] New: static initializer for structs doesn't respect init values of members

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7058

           Summary: static initializer for structs doesn't respect init
                    values of members
           Product: D
           Version: D1 & D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: mrmocool gmx.de



void main()
{
    import std.stdio;
    vec3 v = {1.5f, 2}; // with vec3(1.5f, 2) z becomes 0
    writeln(v);
}

struct vec3
{
//    union
//    {
//        struct
//        {
            float x = 0;
            float y = 0;
            float z = 0;
//        }
//        float[3] cell;
//    }
}

$ dmd -run vector.d
vec3(1.5, 2, nan)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 02 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7058




Interestingly enough, if you add a tuple it only respects the first value at
all:

void main()
{
    import std.stdio;
    vec3 v = {1.5f, 1.f, 0.5f};
    writeln(v);
}

template Tuple(T...)
{
    alias T Tuple;
}

template Repeat(T, int count)
{
    static if (!count)
        alias Tuple!() Repeat;
    else
        alias Tuple!(T, Repeat!(T, count-1)) Repeat;
}

struct vec3
{
    union
    {
        struct
        {
            float x = 0;
            float y = 0;
            float z = 0;
        }
//        float[3] cell;
        Repeat!(float, 3) tuple;
    }
}

$ dmd -run vector.d
vec3(1.5, nan, nan, 1.5, nan, nan)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 02 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7058


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug yahoo.com.au
         Resolution|                            |DUPLICATE



*** This issue has been marked as a duplicate of issue 4967 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 29 2012