This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fix warnings in libobjc
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- To: nicola at brainstorm dot co dot uk
- Cc: gcc-patches at gcc dot gnu dot org, shebs at apple dot com
- Date: Tue, 18 Jun 2002 12:34:00 -0400 (EDT)
- Subject: Re: Fix warnings in libobjc
- References: <Pine.LNX.4.21.0206171842010.1210-100000@nicola.brainstorm.co.uk>
> 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