[bbs@localhost testmisc]$ cat c.c
#include "stdio.h"
struct abc {
char a;
int b;
char c;
};
int main(int a, char** b) {
printf("%d\n", sizeof(struct abc));
return 0;
}
[bbs@localhost testmisc]$ cc c.c -o c
[bbs@localhost testmisc]$ ./c
12
[bbs@localhost testmisc]$ cc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
[bbs@localhost testmisc]$
【 在 atppp (Big Mouse) 的大作中提到: 】
: i686上应该都是32bit吧。其实struct有点BT的,像下面这个结构:
: struct {
: char a;
: int b;
: char c;
: }
: 如果编译设置了诡异的align优化你sizeof一把这个struct没准出来是12,赫赫。
: 普通操作都没问题但是memcpy类似结构就会出问题。所以那个转换程序虽然用memcpy
: 没啥问题但是我觉得这是放弃portability的一种做法。
: 【 在 FlyingFish@coa.cn-bbs.org (人生如梦|抓紧剩下的时间好好工作) 的大作中提到: 】
: ...................
--