Ambiguous C?

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Apr 27 13:27:21 AEST 1989


In article <111 at ssp1.idca.tds.philips.nl> roelof at idca.tds.PHILIPS.nl (R. Vuurboom) writes:
>The intention of the code is to do an int (on the motorola a long) 
>access and then determine the 14th bit.
>The compiler generated a byte access for 2 bytes further and then tested
>the 6th bit.
>Does C specify which (if any) interpretation is correct?

If you tell the compiler that the object being accessed is "volatile",
it should do the best it can to perform the access just the way you
thought you had specified when you wrote the code.  Otherwise it is
entitled to do what it did.

Now, your compiler may not support the "volatile" type qualifier, in
which case you'll need to resort to something else such as assigning
(a copy of) the object to an external variable, which forces the
compiler to pick it all up.  Then you can test the copy for the bit
you were interested in.



More information about the Comp.lang.c mailing list