www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - AA within struct

reply "dominik" <aha aha.com> writes:
what am I doing wrong here?

http://paste.dprogramming.com/dpjd03u4 
Feb 15 2008
parent reply Aarti_pl <aarti interia.pl> writes:
dominik pisze:
 what am I doing wrong here?
 
 http://paste.dprogramming.com/dpjd03u4 
 
 

Struct initialization is different. Try this: public static DST[char[]] AA = [ "Africa/Asmara"[]: {5, "bla"[]} ] ; BR Marcin Kuszczak (aarti_pl)
Feb 15 2008
parent reply "dominik" <aha aha.com> writes:
"Aarti_pl" <aarti interia.pl> wrote in message 
news:fp3rpc$rm5$1 digitalmars.com...
 Struct initialization is different. Try this:

 public static DST[char[]] AA =
         [
             "Africa/Asmara"[]: {5, "bla"[]}
         ]
     ;

yeah I've tried that too: Error: not an associative array initializer I have also tried this: align(1) struct DST { private int test; private char[] secondtest; public static DST[char[]] AA = [ "Africa/Asmara": DST(5, "bla") ] ; } Error: non-constant expression ["Africa/Asmara":(DST(5,"bla"))]
Feb 15 2008
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"dominik" <aha aha.com> wrote in message 
news:fp3s4m$srr$1 digitalmars.com...

 align(1)
 struct DST {

    private int test;
    private char[] secondtest;

    public static DST[char[]] AA =
        [
            "Africa/Asmara": DST(5, "bla")
        ]
    ;
 }

 Error: non-constant expression ["Africa/Asmara":(DST(5,"bla"))]

It's because AA initializers are not constants :P AAs initializers are run at runtime, they cannot be stored in the static data segment so they cannot be constants. You'll have to split it up: public static DST[char[]] AA; static this() { AA = ["Africa/Asmara": DST(5, "bla")]; }
Feb 15 2008
parent "dominik" <aha aha.com> writes:
"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message 
news:fp46ir$1p3l$1 digitalmars.com...
 AAs initializers are run at runtime, they cannot be stored in the static 
 data segment so they cannot be constants.  You'll have to split it up:

thank you!
Feb 15 2008