Ambiguous C?
R. Vuurboom
roelof at idca.tds.PHILIPS.nl
Wed Apr 26 23:36:41 AEST 1989
The following piece of code got me into trouble.
I needed to access a register which only allows long accesses.
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. For locations in memory this will deliver the same result
however a byte access to the register caused a bus timeout error to occur.
There are basically (at least) 2 interpretations to the code:
1. dereference the location as an int then bit and with bit 13. In which
case the generated code is probably wrong.
2. Determine the status of the 14th bit at the given location in which
case the generated code is probably right.
Does C specify which (if any) interpretation is correct?
#define SCUCMD 0
#define SCU_BDID 0x2000 /* bit 14 */
error()
{
if ( (*(int *)(SCUCMD)) & SCU_BDID )
;
}
.text
.globl _error
_error
jra .L40000
.L40001
btst.b #5,2 <== dereferenced as byte
jeq .L13
.L13
.L12
unlk a6
rts
.L40000
link.w a6,#-4
jra .L40001
.data
.data
More information about the Comp.lang.c
mailing list