TR : Possible GCC bug on m68k

Joel Sherrill <joel@OARcorp.com> joel.sherrill at OARcorp.com
Wed Nov 3 12:16:50 UTC 2004


Paul Whitfield wrote:
> 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!

I would have to agree.

I guess I don't use the ~ operator very much.  On bitwise operations,
I tend to be paranoid and mask everything at the end.

> Regards
> 
> 
> Paul
> 


-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel at OARcorp.com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
    Support Available             (256) 722-9985




More information about the users mailing list