An interesting structure!

Laurent R rj45rt at hotmail.com
Mon Nov 28 00:54:45 MST 2005


good, it works.
Thank you all ^_^


>From: Jason Holt <jason at lunkwill.org>
>Reply-To: Provo Linux Users Group Mailing List <plug at plug.org>
>To: Provo Linux Users Group Mailing List <plug at plug.org>
>Subject: Re: An interesting structure!
>Date: Mon, 28 Nov 2005 07:39:07 +0000 (UTC)
>
>
>gcc4 seems to do what you want.
>
>
>[jason at erg] ~$ gcc --version
>gcc (GCC) 4.0.2 (Debian 4.0.2-2)
>Copyright (C) 2005 Free Software Foundation, Inc.
>This is free software; see the source for copying conditions.  There is NO
>warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
>
>[jason at erg] ~$ more foo.c
>#include <stdio.h>
>
>typedef char bool;
>
>struct
>{
>         unsigned short A;
>         bool B;
>         unsigned long C;
>} STR;
>
>main() {
>         int i;
>         STR.B = 1;
>         STR.A = 0x2345;
>         STR.C = 0x6789ABCD;
>         for(i=0; i<sizeof(STR); i++) {
>                 printf("%x ", (unsigned char) (((char *)&STR)[i]));
>         }
>         printf("\n");
>}
>
>[jason at erg] ~$ ./foo
>45 23 1 0 cd ab 89 67
>
>
>[jason at erg] ~$ more bar.c
>#include <stdio.h>
>
>typedef char bool;
>
>struct __attribute ((__packed__))
>{
>         unsigned short A;
>         bool B;
>         unsigned long C;
>} STR;
>
>main() {
>         int i;
>         STR.B = 1;
>         STR.A = 0x2345;
>         STR.C = 0x6789ABCD;
>         for(i=0; i<sizeof(STR); i++) {
>                 printf("%x ", (unsigned char) (((char *)&STR)[i]));
>         }
>         printf("\n");
>}
>
>[jason at erg] ~$ ./bar
>45 23 1 cd ab 89 67
>
>
>/*
>PLUG: http://plug.org, #utah on irc.freenode.net
>Unsubscribe: http://plug.org/mailman/options/plug
>Don't fear the penguin.
>*/

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/




More information about the PLUG mailing list