Re: pragma pack and bitfields
From: David Lowndes (davidl_at_example.invalid)
Date: 09/27/04
- Next message: kalyan.: "error C2143: syntax error : missing ';' before '<class-head>'"
- Previous message: Ronald Laeremans [MSFT]: "Re: Command line warning D4025 : overriding '/EHs' with '/EHa'"
- In reply to: Giovanni Bajo: "Re: pragma pack and bitfields"
- Next in thread: Carl Daniel [VC++ MVP]: "Re: pragma pack and bitfields"
- Reply: Carl Daniel [VC++ MVP]: "Re: pragma pack and bitfields"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 27 Sep 2004 11:07:12 +0100
>-----------------------------------------------
>enum State { ZERO, ONE, TWO };
>
>struct A {
> State s : 2;
>};
>
>void foo(A a) {
> a.s = TWO;
> if (a.s != TWO)
> abort();
>}
>-----------------------------------------------
>
>This aborts. The reason has surely to do with the underlying integer type of
>the bitfield being signed, so that basically 's' represents "-2" after
>assignment, and fails the comparison with two. Do you have a workaround for a
>situation like this?
Other than not using the enum as the bitfield type or otherwise
fiddling with the value, I'm afraid not.
>GCC works as expected.
I can imagine reasons for both possibilities, but I'm not familiar
enough with the C++ standards to know what it really should be.
Carl, can you comment on this?
Dave
-- MVP VC++ FAQ: http://www.mvps.org/vcfaq
- Next message: kalyan.: "error C2143: syntax error : missing ';' before '<class-head>'"
- Previous message: Ronald Laeremans [MSFT]: "Re: Command line warning D4025 : overriding '/EHs' with '/EHa'"
- In reply to: Giovanni Bajo: "Re: pragma pack and bitfields"
- Next in thread: Carl Daniel [VC++ MVP]: "Re: pragma pack and bitfields"
- Reply: Carl Daniel [VC++ MVP]: "Re: pragma pack and bitfields"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|