TR : Possible GCC bug on m68k

Etienne Fortin etienne.fortin at sensio.tv
Tue Nov 2 20:54:04 UTC 2004


Hi everyone,
I know I should put this on the GCC forum, but I want to be sure that
I'm not mystaken with the behavior I'll describe.

I have the following code:
    packet->number = (unsigned char)fgetc(sender);
    comp = (unsigned char)fgetc(sender);
    if(packet->number != ~comp)
        return EIO;

packet->number = 0 and comp = 0xFF.

We would presume that return EIO will NOT be taken. But in fact, it is.

I dissaembled the code and found out that the compiler generated a
comparison between d0 and d1 register, and that d0=0x00000000 and
d1=0xFFFFFF00!!! It seems that the code generated by GCC assumes words
when bytes are compared. The compiler should generate code that make
sure only the byte of the register is significant in the comparison. But
it does not.

Is it a bug? a known behavior? A newbie thing? :)

And by the way, modifying the above code like this makes it work:

    packet->number = (unsigned char)fgetc(sender);
    comp = (unsigned char)fgetc(sender);
    if(packet->number != (~comp & 0xFF))
        return EIO;


Etienne Fortin
Sensio




More information about the users mailing list