dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [DotGNU]a segfault on anonymous bit field


From: Rhys Weatherley
Subject: Re: [DotGNU]a segfault on anonymous bit field
Date: Thu, 29 Aug 2002 09:06:00 +1000

Gopal V wrote:
> 
> This is a stupid bug report ... but it does have some sense in it
> 
> struct xyz
> {
>         int x:1;
>         int y:2;
>         int z:3;
>         int :2;
> };
> 
> should compile ... but throws an error with cscc (A segfault)....

Whoops.  Your fix was fine, but I decided to do it another
way.  There's no need to add the "BitFieldAttribute" instance
to the class for anonymous bit fields, as there is no way
to reference them by name.  I avoid the SEGV by not calling
the function in the first place.

> Also the aspect of sizeof came up here . sizeof(struct xyz) was
> not 1 as expected, it was 4 ... why ? (saw an ldc.i4.4 there)
> So are all bitsets stored in Int32s ? (I wanted to access a byte here,
> I can't union with a byte here ...)

The size of the structure is based on the size of the
representation type.  In this case, "int", which is 4
bytes in size.  If you want a 1-byte structure, then
use this:

struct xyz
{
        char x:1;
        char y:2;
        char z:3;
        char :2;
};

This behaviour is consistent with gcc.  The types "char",
"unsigned char", "short", "unsigned short", "int", "unsigned
int", "long", "unsigned long", "long long", and "unsigned
long long" may be used as the type of a bit field, depending
upon the underlying representation size that is desired.
Signed types give signed bit fields, and unsigned types give
unsigned bit fields.

Cheers,

Rhys.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]