digitalmars.D.learn - Compile time static array issues.
- Era Scarecrow <rtcvb32 yahoo.com> May 28 2011
- Robert Clipsham <robert octarineparrot.com> May 28 2011
- Era Scarecrow <rtcvb32 yahoo.com> May 28 2011
- bearophile <bearophileHUGS lycos.com> May 28 2011
- Era Scarecrow <rtcvb32 yahoo.com> May 29 2011
- Jacob Carlborg <doob me.com> May 29 2011
- bearophile <bearophileHUGS lycos.com> May 29 2011
- Jacob Carlborg <doob me.com> May 29 2011
- bearophile <bearophileHUGS lycos.com> May 29 2011
- Andrej Mitrovic <andrej.mitrovich gmail.com> May 29 2011
- Andrej Mitrovic <andrej.mitrovich gmail.com> May 29 2011
I don't seem to have a good explanation why this isn't working. All i end up
getting is 'Error: cannot implicitly convert expression .... of type
string[][] to joined[]'. I also get 'incompatible types for (("AADT") ? (16)):
'string' and 'int''. I've tried it with casts, and full array qualifiers.
I'm using DMD 2.053.
--
struct joined {
string name;
string partof;
string preReq;
}
struct subrecord_parts {
string name;
int size;
string[] notes;
int identifyBy;
int[] partSize;
}
joined[] attached;
subrecord_parts[] parts;
static this() {
attached = [
["MAST", "DATA", "TES3"],
["ANAM","INTV", "FACT"]];
parts = [
["AADT", 16, ["fWeight", "iValue", "iUses", "fQuality"], -1, [4,4,4,4]],
["AODT", 24, ["iType", "fWeight", "iValue", "iHealth", "iEnchant Points",
"iArmour"], -1, [4,4,4,4,4,4]]];
}
-- output
test.d(20): Error: cannot implicitly convert expression
([["MAST","DATA","TES3"],["ANAM","INTV","FACT"]]) of type string[][] to joined[]
Error: incompatible types for (("AADT") ? (16)): 'string' and 'int'
Error: incompatible types for (("AODT") ? (24)): 'string' and 'int'
test.d(26): Error: cannot implicitly convert expression
([[(__error),(__error),(__error),(__error),(__error)],[(__error),(__error),(__error),(__error),(__error)]])
of type _error_[][] to subrecord_parts[]
May 28 2011
On 28/05/2011 23:57, Era Scarecrow wrote:I don't seem to have a good explanation why this isn't working. All i end up getting is 'Error: cannot implicitly convert expression .... of type string[][] to joined[]'. I also get 'incompatible types for (("AADT") ? (16)): 'string' and 'int''. I've tried it with casts, and full array qualifiers. I'm using DMD 2.053. -- struct joined { string name; string partof; string preReq; } struct subrecord_parts { string name; int size; string[] notes; int identifyBy; int[] partSize; } joined[] attached; subrecord_parts[] parts; static this() { attached = [ ["MAST", "DATA", "TES3"], ["ANAM","INTV", "FACT"]];
try attached = [joined("MAST", "DATA", "TES3"), joined("ANAM", "INTV", "FACT")];parts = [ ["AADT", 16, ["fWeight", "iValue", "iUses", "fQuality"], -1, [4,4,4,4]], ["AODT", 24, ["iType", "fWeight", "iValue", "iHealth", "iEnchant Points", "iArmour"], -1, [4,4,4,4,4,4]]];
Similar here, parts = [ subrecord_parts("AADT", 16, ["fWeight", "iValue", "iUses", "fQuality"], -1, [4,4,4,4]), subrecord_parts(...)]; etc.} -- output test.d(20): Error: cannot implicitly convert expression ([["MAST","DATA","TES3"],["ANAM","INTV","FACT"]]) of type string[][] to joined[] Error: incompatible types for (("AADT") ? (16)): 'string' and 'int' Error: incompatible types for (("AODT") ? (24)): 'string' and 'int' test.d(26): Error: cannot implicitly convert expression ([[(__error),(__error),(__error),(__error),(__error)],[(__error),(__error),(__error),(__error),(__error)]]) of type _error_[][] to subrecord_parts[]
-- Robert http://octarineparrot.com/
May 28 2011
== Quote from Robert Clipsham (robert octarineparrot.com)'s articleOn 28/05/2011 23:57, Era Scarecrow wrote: try attached = [joined("MAST", "DATA", "TES3"), joined("ANAM", "INTV", "FACT")];
Similar here, parts = [ subrecord_parts("AADT", 16, ["fWeight", "iValue", "iUses", "fQuality"], -1, [4,4,4,4]), subrecord_parts(...)]; etc.
I was certain I tried that already. But it compiles now. Perhaps I just didn't do enough of them to confirm if it was working. Thanks
May 28 2011
Era Scarecrow:I don't seem to have a good explanation why this isn't working.
Also try: struct Joined { string name, partof, preReq; } struct SubrecordParts { string name; int size; string[] notes; int identifyBy; int[] partSize; } Joined[] attached = [ {"MAST", "DATA", "TES3"}, {"ANAM","INTV", "FACT"} ]; SubrecordParts[] parts = [ {"AADT", 16, ["fWeight", "iValue", "iUses", "fQuality"], -1, [4,4,4,4]}, {"AODT", 24, ["iType", "fWeight", "iValue", "iHealth", "iEnchant Points", "iArmour"], -1, [4,4,4,4,4,4]} ]; void main() {} In D struct names are (usually) CamelCase. Bye, bearophile
May 28 2011
== Quote from bearophile (bearophileHUGS lycos.com)'s articleAlso try: struct Joined { string name, partof, preReq; } Joined[] attached = [ {"MAST", "DATA", "TES3"}, {"ANAM","INTV", "FACT"} ];
Coming from C, this is exactly what I first tried. However since I don't recall the {}'s being used in D it ended up using []'s, which sounds right and yet doesn't at the same time. Like this (Which is broken). Joined[] attached = [ ["MAST", "DATA", "TES3"], ["ANAM","INTV", "FACT"] ]; Doing a search I got the impression I had to use 'static this()'. Thanks bearophile. Let's hope I don't need much more help later :P
May 29 2011
On 2011-05-29 03:56, bearophile wrote:Era Scarecrow:I don't seem to have a good explanation why this isn't working.
Also try: struct Joined { string name, partof, preReq; } struct SubrecordParts { string name; int size; string[] notes; int identifyBy; int[] partSize; } Joined[] attached = [ {"MAST", "DATA", "TES3"}, {"ANAM","INTV", "FACT"} ]; SubrecordParts[] parts = [ {"AADT", 16, ["fWeight", "iValue", "iUses", "fQuality"], -1, [4,4,4,4]}, {"AODT", 24, ["iType", "fWeight", "iValue", "iHealth", "iEnchant Points", "iArmour"], -1, [4,4,4,4,4,4]} ]; void main() {} In D struct names are (usually) CamelCase. Bye, bearophile
Isn't that struct initialization syntax deprecated or to be deprecated? -- /Jacob Carlborg
May 29 2011
Jacob Carlborg:Isn't that struct initialization syntax deprecated or to be deprecated?
You may be right. Sometimes I read about deprecations, and then after a while I forget it because the alternative (like using the complex numbers of Phobos) is too much ugly by comparison :-) I think we need an official deprecation list page, that includes a good rationale for each of the deprecated things. Bye, bearophile
May 29 2011
On 2011-05-29 15:01, bearophile wrote:Jacob Carlborg:Isn't that struct initialization syntax deprecated or to be deprecated?
You may be right. Sometimes I read about deprecations, and then after a while I forget it because the alternative (like using the complex numbers of Phobos) is too much ugly by comparison :-) I think we need an official deprecation list page, that includes a good rationale for each of the deprecated things. Bye, bearophile
The would be very helpful. There are too many messages like the one from above from me. -- /Jacob Carlborg
May 29 2011
Andrej Mitrovic:C struct initialization in D is also buggy, it doesn't take into account field initializers. It's best to get used to the D way of initializing structs.
I'd like it to be debugged instead :-) Bye, bearophile
May 29 2011
C struct initialization in D is also buggy, it doesn't take into account field initializers. It's best to get used to the D way of initializing structs.
May 29 2011
On 5/29/11, bearophile <bearophileHUGS lycos.com> wrote:Andrej Mitrovic:C struct initialization in D is also buggy, it doesn't take into account field initializers. It's best to get used to the D way of initializing structs.
I'd like it to be debugged instead :-)
Well if it has already been decided that they're going away, no point in debugging them! :) Although I have to say, porting C code with struct initializers to D is a pain in the ass. Maybe I need a Vim script to do that or something, heh..
May 29 2011









Era Scarecrow <rtcvb32 yahoo.com> 