Skip to contentSkip to conversation

C undefined behavior fix

PATCH mike stump 1 participant 1 message Jan 7, 2002

lore
Share & tools
lore

mike stump

author
#0 lore raw
Quoted 10 lines

From: Bernard Dautrevaux <[email protected]>
To: "'[email protected]'" <[email protected]>, [email protected]
Cc: [email protected], [email protected], [email protected],
[email protected]
Date: Mon, 7 Jan 2002 14:24:35 +0100

Truly sure; In fact when writiong our Real Time Kernel in C++ we just had this problem, and had to "hack" GCC C and C++ compilers so that volatile acesses are guaranteed to be done with the right size, even in case of bit fields in fact.

Did your case include more than bitfields? I recognize that bitfields have two possible semantics, and that you and gcc may have different opinions about the semantics of them. I discount the alternative choice of semantic as being an example of this problem. Roughly speaking, as I recall... The two semantics are, the base type of the bitfield defines the mode in which memory is accessed and the smallest size supported that contains the bitfield defines the access.

struct { unsigned int field:8; };

would be a 32 bit access, versus

struct { unsigned int field:8; };

would be an 8 bit access.

If gcc doesn't do one of them, it truly is broken (if the machine supports the access of course). I would like to know if gcc is truly broken.

Quoted 2 lines

Using volatile (and expanding its semantics to mean: read and write with the requested size) was a great help.

In gcc, it already means that. If you think otherwise, I'd like to see the example that shows it.