From: G DOT DegliEsposti AT ads DOT it To: massarin AT alpha3 DOT cram DOT enel DOT it cc: djgpp AT delorie DOT com Message-ID: Date: Tue, 21 Apr 1998 17:21:32 +0200 Subject: Re: Struct with array. HELP Mime-Version: 1.0 Content-type: text/plain; charset=us-ascii Precedence: bulk >My problem is that when I declare a struct like: > >struct a { > char b[n]; > int c; > . > . > . } > >if n (number of char in array) is not a multiple of 4 >the array is enlarged to fit a 4' multiple, > >n=32 int c is 32 byte from start of struct >n=33 int c is 36 byte from start of struct > >I've verified it with GDB and doing sizeof(struct a). > >Does anyone know how to make the struct, and the array, of >the proper size ,apart from doing the struct as an array ? >Is it a bug of compiler ? AFAIK there is no portable way of doing this. gcc has some extensions like the __attribute__ ((packed)) specifier you can append to the declaration of the struct: struct { ... } __attribute__ ((packed)); You can find more info in section 22.9 of the djgpp FAQs or within djgpp docs (info gcc "c extensions" "type attributes") ciao Giacomo