🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #6249

sizeof() on bitfield structs seems inconsistent

#6249
From: Mike Figley
Date: Tue, 26 Dec 1995 00:00
36 lines
1294 bytes
#include <stdio.h>
/*
Headline: sizeof() seems inconsistant on bitfields.
gcc = 2.7.0
os = sunos 4.1.4
Issue: it seems that both of the following
structures would fit in one "machine" word.

Mike Figley
figley@grinnel.sps.mot.com
*/

struct PTrascii1 { /* 32 bits/4 bytes, but my system sez "5" */
  unsigned short :14;
  unsigned char c1:6; 
  unsigned char c2:6;
  unsigned char :6;
} pt1;

struct PTrascii2 { /* 32 bits/4 bytes, but my system sez "6" */
  unsigned short pad1:14; /* if this is a long, it sez "8" */
  unsigned char c1:6; 
  unsigned char c2:6;
  unsigned char pad2:6;
} pt2;

int main(void) {
int a,b;

printf( "\nsizeof(PTrascii1):%d should  ==  sizeof(PTrascii2):%d\n",
	(a=sizeof(pt1)),(b=sizeof(pt2)));
printf( "Seems like they should both be \"4\".\n");

if ((a==b)&&(a==4)) exit(0);
exit(1);
}
Technical Details
Message-ID: <9512262019.AA27653@grinnel.MDAD_advtst>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113d02,ab367d9ec3b95b0,start
X-Google-Attributes: gid113d02,public
From: figley@grinnel.sps.mot.COM (Mike Figley)
Subject: sizeof() on bitfield structs seems inconsistent
Date: 1995/12/26
Message-ID: <9512262019.AA27653@grinnel.MDAD_advtst>
X-Deja-AN: 122884943
distribution: gnu
sender: daemon@cis.ohio-state.edu
organization: GNUs Not Usenet
newsgroups: gnu.gcc.bug