Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!ncar!boulder!hartzell From: hartzell@boulder.colorado.edu (George Hartzell) Newsgroups: comp.sys.mips Subject: mips cc "shortcoming" with compile time array initializtion. Message-ID: <21901@boulder.Colorado.EDU> Date: 5 Jun 90 18:33:22 GMT Sender: news@boulder.Colorado.EDU Reply-To: hartzell@beagle (George Hartzell) Organization: University of Colorado, Boulder Lines: 46 The following test program compiles and runs on suns (SUNos 4.0x, sun4), but will not compile on a MIPS with the 2.0 compilers or a DECstation with the 1.31 compiler suite. There error message is (this is from the DECstation) ccom: Error: moose.c, line 8: constant expected static int ia[] = { ((char *) &X.a - (char *) &X), ((char *) X.b - (cha r *) &X), ((char *) &X.c - (char *) &X) } ; --------------------------------------------------^ ccom: Error: moose.c, line 8: illegal initialization static int ia[] = { ((char *) &X.a - (char *) &X), ((char *) X.b - (cha r *) &X), ((char *) &X.c - (char *) &X) } ; --------------------------------------------------^ This also works on gcc for the DECstation... I have two questions: a) should this be legal [in the ansi sense?, in the practical sense?] (The compiler should have all the info it needs to figure this out, shouldn't it?) b) do the 2.10 compilers support this construction? g. -----cut here for sample program -------------------------------------------- #define CharAttI(a) ((char *) X.a - (char *) &X) #define AttIndex(a) ((char *) &X.a - (char *) &X) typedef struct { int a; char b[8]; int c; } Thing; static Thing X; static int ia[] = { AttIndex(a), CharAttI(b), AttIndex(c) } ; main() { printf( "\nia: %d %d %d\n", ia[0], ia[1], ia[2] ) ; } George Hartzell (303) 492-4535 MCD Biology, University of Colorado-Boulder, Boulder, CO 80309 hartzell@Boulder.Colorado.EDU ..!ncar!boulder!hartzell