On Fri, Mar 24, 2006 at 06:03:49PM +0100, Joerg Schilling wrote: >Steve Bennett <[EMAIL PROTECTED]> wrote: > >> Joerg Schilling wrote: >> > Did you test with a recent GCC using >> > >> > #pragma pack(1) >> > >> > I would expect that this also results in reduced sizes. >> >> Yes, I certainly have tested it (and Steve said he had too). >> It does not work. > >"Does not work" does not really help..... > >> > <nslu2> gcc -dumpversion >> > 4.0.3 >> >> Which is just about as recent as it gets. >> >> I believe that #pragma pack(1) affects inter-field padding, >> but does not affect padding at the end of structures. > >From the forst text from you, I asume that the problem is that the size >of char[4] is not 4 but 16.
No, it's not. >So where is the real problem? Quick demonstration: 1. gcc on an i386 box: smcintyre:~$ gcc -v Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.5/specs Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --enable-__cxa_atexit --with-system-zlib --enable-nls --without-included-gettext --enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc i486-linux Thread model: posix gcc version 3.3.5 (Debian 1:3.3.5-13) smcintyre:~$ uname -a Linux smcintyre 2.6.13 #5 SMP Mon Sep 26 16:04:46 BST 2005 i686 GNU/Linux smcintyre:~$ ./wibble sizeof(test1) is 10 sizeof(test2) is 10 2. gcc on an arm box: [EMAIL PROTECTED]:~$ gcc -v Reading specs from /usr/lib/gcc-lib/arm-linux/3.3.5/specs Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --enable-__cxa_atexit --with-system-zlib --enable-nls --without-included-gettext --enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc arm-linux Thread model: posix gcc version 3.3.5 (Debian 1:3.3.5-13) [EMAIL PROTECTED]:~$ uname -a Linux grieg 2.4.27-netwinder #1 Sun Dec 4 21:39:55 UTC 2005 armv4l GNU/Linux [EMAIL PROTECTED]:~$ ./wibble sizeof(test1) is 10 sizeof(test2) is 12 Both are using the following source: #include <stdio.h> struct test1 { char blerg[1]; char type[4]; char flibble[3]; char more[2]; } __attribute__((packed)); #pragma pack(1) struct test2 { char blerg[1]; char type[4]; char flibble[3]; char more[2]; }; int main (int argc, char **argv) { printf("sizeof(test1) is %d\n", sizeof(struct test1)); printf("sizeof(test2) is %d\n", sizeof(struct test2)); return 0; } As the link that I posted up-thread said, #pragma pack(1) does not force alignment within a structure on arm, as that would clash with the arm ABI. If you _must_ do things that way, you have to use __attribute__((packed)). Better/more portable would be to have a simple byte array rather than a packed structure. -- Steve McIntyre, Cambridge, UK. [EMAIL PROTECTED] There's no sensation to compare with this Suspended animation, A state of bliss -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]