This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix warnings in libobjc


 > From: Nicola Pero <nicola@brainstorm.co.uk>
 > 
 > swap.m:
 > =======
 > #include <stdio.h>
 > 
 > int main()
 > {
 >   union swap 
 >     {
 >       unsigned short num;
 >       unsigned char  byt[2];
 >     } dst;
 >   unsigned short i, j;
 >   union swap *src; 
 >   
 >   i = 0x456;
 > 
 >   src = (union swap*)&i;
 >   dst.byt[0] = src->byt[0];
 >   dst.byt[1] = src->byt[1];
 >   j = dst.num;
 >   
 >   if (j != 0x456)
 >     {
 >       printf ("Test error: j == %x\n", j);
 >       abort ();
 >     }
 >   return 0;
 > }

I think this test only works if sizeof(short) == 2.
That's true on most cpus in gcc, but not all IIRC.

Perhaps if you change the size of `byt' to be:

 >   union swap
 >     {
 >       unsigned short num;
 >       unsigned char  byt[sizeof(unsigned short)];
 >     } dst;

and then loop over sizeof(src->byt) for assigning dst it'll be ok for
all cases.  E.g.:

 >   unsigned short x;
 >   src = (union swap*)&i;
 >   for (x=0; x < (sizeof(src->byt)); x++)
 >     dst.byt[x] = src->byt[x];
 >   j = dst.num;


		--Kaveh
--
Kaveh R. Ghazi			Director of Systems Architecture
ghazi@caip.rutgers.edu		Qwest Solutions


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]