www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/21/11:32:06

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: <C12565ED.0053B6F1.00@vega.ads.it>
Date: Tue, 21 Apr 1998 17:21:32 +0200
Subject: Re: Struct with array. HELP
Mime-Version: 1.0




>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



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019