cc compiler warning question.

Martin Serrer SERRER at NRCM3.NRC.CA
Sat Nov 17 05:54:00 AEST 1990


Hello c'ers,
  I am trying to define and access a data structure 'zero' which contains an
array of structures 'one' , the size of which is not know until run time. No
problem right?  When I compile this code I get warnings about 'illegal zero
sized structure member'. The code runs properly but I'm worried about the
warnings. What rules am I breaking?? (see the evidence below)

  Please be gentle as I am still learning about c.
Thanks in advance... Martin

BTW. this is on a 4D50/GT IRIX 3.2

-------------------------------evidence-----------------------------------------
% cat t.c
#include <stdio.h>

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;
      --^
ccom: Warning: t.c, line 28: struct/union or struct/union pointer required
        zero->one[0].c = 2;
      ---------------^
ccom: Warning: t.c, line 29: struct/union or struct/union pointer required
      printf("--- %i\n",zero->one[0].c);
      -------------------------------^

% t
--- 1
--- 2

+-----------------------------------------------------------------------------+
| Martin Serrer                           Systems Lab., Bldg. M2, Montreal Rd.|
| 613-993-9442                            National Research Council of Canada,|
| serrer at syslab.nrc.ca                    Ottawa,  Ontario,  Canada  K1A-0R6  |
+------------------- Software Rusts, Rust never Sleeps -----------------------+



More information about the Comp.sys.sgi mailing list