www.digitalmars.com         C & C++   DMDScript  

D - Associative array strangeness.

reply Andy Friesen <andy ikagames.com> writes:
A char[char[]] is an array of chars, indexed by char[]s, but a 
char[][char[]] is, as far as the compiler seems to be concerned, an 
array of char[][]s, indexed by char[]s.

Am I missing something obvious, or is this really weird? :)
May 04 2003
parent reply Burton Radons <loth users.sourceforge.net> writes:
Andy Friesen wrote:
 A char[char[]] is an array of chars, indexed by char[]s, but a 
 char[][char[]] is, as far as the compiler seems to be concerned, an 
 array of char[][]s, indexed by char[]s.
It would be a bug, but I have code using char[][char[]] successfully with the intended meaning. How does the compiler "[seem] to be concerned"?
May 04 2003
parent reply Andy Friesen <andy ikagames.com> writes:
Burton Radons wrote:
 Andy Friesen wrote:
 
 A char[char[]] is an array of chars, indexed by char[]s, but a 
 char[][char[]] is, as far as the compiler seems to be concerned, an 
 array of char[][]s, indexed by char[]s.
It would be a bug, but I have code using char[][char[]] successfully with the intended meaning. How does the compiler "[seem] to be concerned"?
ooooookay. I can't reproduce it now, but I was getting a "cannot convert char[][] to char[]" error when trying to extract an element from a char[][char[]].
May 04 2003
parent reply "Sean L. Palmer" <palmer.sean verizon.net> writes:
Maybe it works as:

(char[])[char[]] x;

or

char[char[]][] x;

or

char( x[char[]] )[];

?

C-style typespecs always were confusing.  I haven't kept track of how D
typespecs improve upon C.  It's certainly not readable left-to-right.

I assume you're after an associative array mapping strings to strings?

alias char[] string;
string[string] x;

I'm also assuming that D, like C, allows grouping of parts of typespecs by
explicit parenthesis.  I haven't checked.

Walter, care to clarify?

Sean

"Andy Friesen" <andy ikagames.com> wrote in message
news:b943oa$1nh3$1 digitaldaemon.com...
 Burton Radons wrote:
 Andy Friesen wrote:

 A char[char[]] is an array of chars, indexed by char[]s, but a
 char[][char[]] is, as far as the compiler seems to be concerned, an
 array of char[][]s, indexed by char[]s.
It would be a bug, but I have code using char[][char[]] successfully with the intended meaning. How does the compiler "[seem] to be
concerned"?

 ooooookay.

 I can't reproduce it now, but I was getting a "cannot convert char[][]
 to char[]" error when trying to extract an element from a char[][char[]].
May 04 2003
parent "Walter" <walter digitalmars.com> writes:
"Sean L. Palmer" <palmer.sean verizon.net> wrote in message
news:b94ajf$1tdq$1 digitaldaemon.com...
 Maybe it works as:

 (char[])[char[]] x;

 or

 char[char[]][] x;

 or

 char( x[char[]] )[];

 ?

 C-style typespecs always were confusing.  I haven't kept track of how D
 typespecs improve upon C.  It's certainly not readable left-to-right.

 I assume you're after an associative array mapping strings to strings?

 alias char[] string;
 string[string] x;

 I'm also assuming that D, like C, allows grouping of parts of typespecs by
 explicit parenthesis.  I haven't checked.

 Walter, care to clarify?
It works left-to-right, not inside-out as C does. As such, paretheses are not necessary.
Jul 15 2003