Path: utzoo!attcan!uunet!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!brl.mil!moss From: moss@brl.mil (Gary S. Moss (VLD/VMB) ) Newsgroups: comp.sys.sgi Subject: Re: cc compiler warning question. Message-ID: <14524@smoke.brl.mil> Date: 19 Nov 90 15:08:09 GMT References: <032D013E619F0000A3@NRCNET.NRC.CA> Sender: news@smoke.brl.mil Reply-To: moss@brl.mil Organization: Ballistic Research Laboratory Lines: 54 In article <032D013E619F0000A3@NRCNET.NRC.CA>, SERRER@NRCM3.NRC.CA (Martin Serrer) writes: |> #include |> |> typedef struct { int a; int b; } TINY; |> typedef struct { TINY two; int c; } SMALL; |> typedef struct { SMALL *one[]; int f; } BIG; |> BIG *zero; |> |> main() |> { zero = (BIG *) malloc( (sizeof(BIG) + sizeof(SMALL) * 2) ); |> zero->f = 1; |> zero->one[0].c = 2; |> printf("--- %i\n",zero->f); |> printf("--- %i\n",zero->one[0].c); |> } |> |> % cc t.c |> ccom: Warning: t.c, line 18: illegal zero sized structure member: one |> } BIG; |> --^ You are declaring "one" as an array of unspecified, therefore zero size, declare it as "SMALL **one;" instead. In this context, there is a big difference between the two declarations; the compiler knows how big a "SMALL **" is. |> ccom: Warning: t.c, line 28: struct/union or struct/union pointer required |> zero->one[0].c = 2; |> ---------------^ You must use "->" rather than ".": In the declaration "SMALL *one[];", one is an array of pointers to SMALL types. Therefore, one[0] is a pointer and requires a "->" after it, not a ".". |> ccom: Warning: t.c, line 29: struct/union or struct/union pointer required |> printf("--- %i\n",zero->one[0].c); |> -------------------------------^ Same thing as above. You will also need to allocate storage for "one" separately from "zero": if( (zero = (BIG *) malloc( sizeof(BIG) )) == NULL || (zero->one = (SMALL *) malloc( sizeof(SMALL) * 2 )) == NULL ) { /* ALWAYS check success of malloc(3). */ (void) fprintf( stderr, "No memory available!\n" ); return 1; } Of course, you *could* declare storage for zero like this: BIG zero; Rather than the first call to malloc, and leave your "."s as they are. -Gary