TR : Possible GCC bug on m68k
Etienne Fortin
etienne.fortin at sensio.tv
Wed Nov 3 13:07:41 UTC 2004
Thanks Paul for that well documented clarification. I just learned
something else about C!
Etienne Fortin
Sensio
-----Message d'origine-----
De : Paul Whitfield [mailto:paulw at omnitronics.com.au]
Envoyé : 3 novembre, 2004 01:07
À : rtems-users
Objet : Re: RE : RE : RE : TR : Possible GCC bug on m68k
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