Article View: gnu.gcc.bug
Article #6106Re: bit field problem
From: Jeremy Greene
Date: Thu, 28 Nov 1996 00:00
Date: Thu, 28 Nov 1996 00:00
70 lines
2464 bytes
2464 bytes
> While the gcc maintainers might consider this something to fix, it
> is not technically a bug, nor is the bitfield technically responsible
> for the problem.
Well, in general, I disagree... forcing alignment is one thing. Access
of aligned data should always adhere to the defined data type. But I'm
not the one writing the compiler :)
However, even if I did, I think this is separate bug:
o The original example I supplied was over-simplified. If a
'naturally' aligned structure is created, the problem still
existis. See below.
o If I force alignement (which I shouldn't have to do in the example
below, the problem still exists. For protocol support this is a
major problem. Yes, I know that structs defining protocol headers
should never use bit-fields, but this is ported code.
And last, but far from least...
o I think the example below actually loads data from the following
fields!!
In the end, I'll probably just ahve to bite the bullet and change the
code not to use bit-fields. However, I'd say that if this were a
problem with regualr chars too, most networking software would not
work.
Jeremy
/* behves the same without the aligned attributes
*/
struct Bits
{
/* if there's a bit field:
*/
unsigned char y:4, x:4 __attribute__ ((aligned (1)));
char pad __attribute__ ((aligned (1)));
char pad2 __attribute__ ((aligned (1)));
char pad3 __attribute__ ((aligned (1)));
/* if the following is present, the above bit field does a int
* fetch... apparently through pad3!
*/
int possitiveAlignemnt __attribute__ ((aligned (1)));
} __attribute__ ((aligned (1)));
int main()
{
char data[30];
register struct Bits *bits;
bits = &data[2];
printf("%d\n", sizeof(struct Bits));
/* I think the folling is loading through pad3!!!
*/
bits->y = 5;
return 0;
}
Technical Details
Message-ID:
<633cab136ec6d443cd945c0adad8493c@wretched.mailer.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 113d02,766ce23cf280fcf1 X-Google-Attributes: gid113d02,public From: jeremy@xedia.com (Jeremy Greene) Subject: Re: bit field problem Date: 1996/11/28 Message-ID: <633cab136ec6d443cd945c0adad8493c@wretched.mailer.com> X-Deja-AN: 201316934 sender: bug-gcc-request@prep.ai.mit.edu x-gateway: wendy-fate.uu.net from bug-gcc to gnu.gcc.bug; Thu, 28 Nov 1996 20:46:14 EST return-path: <gnulists-usenet-ownrr@prep.ai.mit.edu> newsgroups: gnu.gcc.bug