TR : Possible GCC bug on m68k

Paul Whitfield paulw at omnitronics.com.au
Wed Nov 3 06:07:14 UTC 2004


Chris Johns wrote:
>>
> 
> Hmmm. What about this example:
> 
> /* m68k-rtems-gcc -g -c -o comp.o comp.c */
> #include <stdio.h>
> int main ()
> {
>         unsigned char l = 0xff;
>         unsigned char r = 0;
>         if (l == ~r)
>                 printf ("i) yes\n");
>         else
>                 printf ("i) no\n");
>         if (l == (unsigned char) ~r)
>                 printf ("ii) yes\n");
>         else
>                 printf ("ii) no\n");
>         return 0;
> }
> 
> The result on Linux is :
> 
> $ ./comp
> i) no
> ii) yes

On windows with gcc ... result the same
On windows with BorlandC ... result the same...


For K&R Version 2: A.7.4.6 One's Complement Operator.

The operand of the ~ operator must have integral type, and the result is
the one's complement of its operand. The integral promotions are
performed.  If the operand is unsigned, the result is computed
by subtracting the value from the largest value of the promoted type.

...

So to me (and I am not a language lawyer)... it would seem that
the operation is correct!

Regards


Paul




More information about the users mailing list