Re: [PATCH] C undefined behavior fix

Bernd Petrovitsch
2002-01-10T10:44:40Z

In message <20020109204043.T1027-100000@gerard>, G rard Roudier wrote:
>On Tue, 8 Jan 2002, J.A. Magallon wrote:
>> On 20020107 jtv wrote:
>> >
>> >Let's say we have this simplified version of the problem:
>> >
>> > int a = 3;
>> > {
>> > volatile int b = 10;
>>
>> >>>>>>>>> here b changes
>
>Hmmm...
>Then your hardware is probably broken or may-be you are dreaming. :-)

No, it may be e.g. a Rx/Tx-register in a standard UART chip, which is
memory-mapped at some address. Actually reading and writing the same
address then would get different registers in the hardware. Reading
two times may get different values.
You would actually access this register through a "volatile char *"
but that's not a significant difference to the concept of "volatile",
so I see above as a simple example (and not as an optimizer-guru's
discussion subject "can we optimize just this volatile expression in
that context").

>There is nothing in this code that requires the compiler to allocate
>memory for 'b'. You just invent the volatile constant concept. :)

Nope, this existed before as jtv@xs4all.nl explained correctly.

Bernd
--
Bernd Petrovitsch Email : bernd@gams.at
g.a.m.s gmbh Fax : +43 1 205255-900
Prinz-Eugen-Straße 8 A-1040 Vienna/Austria/Europe
LUGA : http://www.luga.at