Article View: gnu.gcc.bug
Article #743Bitfield messes up sizeof()
From: f
Date: Sat, 21 Oct 1989 21:19
Date: Sat, 21 Oct 1989 21:19
37 lines
1777 bytes
1777 bytes
Using gcc 1.35 on a sun4:
Apparently, including bitfields in a structure definition messes up
the compiler's computation of the correct size of the structure.
gcc reports sizeof(ResultStruct) is 6, while sizeof(ResultStruct2) is 8.
The correct answer is 8, because of alignment issues on the sun4.
typedef struct NSR {
poslongnumber thestate : 24; /* if thestate&(1<<23), actual state is
-(thestate&((1<<23)-1)) in the call chain */
poslongnumber inp : 1; /* was there input in producing this state? */
poslongnumber outp : 1; /* was there output from this state? */
poslongnumber bits : 4; /* the bits for this state */
poslongnumber last : 1; /* TRUE iff I am last in sequence. */
poslongnumber misc : 1; /* pad to 32 bits */
} NSR, * NSRP;
/* all uninitialized NSRs look like NONSR, which is guaranteed not to match
anything real NSR. */
extern NSR NONSR;
/* the NSR0 has everything set to 0 */
extern NSR NSR0;
/* a structure that remembers the state and the char */
typedef struct ResultStruct {
NSR thensr;
posnumber inchar; /* input char after translation */
} ResultStruct, * ResultStructP;
typedef struct ResultStruct2 {
longnumber foo;
posnumber inchar;
} ResultStruct2, * ResultStruct2P;
-steve
Technical Details
Message-ID:
<6557@columbia.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!columbia!read.columbia.edu!References:
<17438@watdragon.waterloo.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!columbia!read.columbia.edu! From: @read.columbia.edum) (f) Newsgroups: gnu.gcc.bug Subject: Bitfield messes up sizeof() Keywords: bitfields, sizeof Message-ID: <6557@columbia.edu> Date: 21 Oct 89 21:19:54 GMT References: <17438@watdragon.waterloo.edu> Sender: news@columbia.edu Reply-To: kearns@cs.columbia.edu Organization: Columbia University Department of Computer Science Lines: 37