- 论坛徽章:
- 0
|
# gcc -Wall -o test test.c
# ./test
test = ffffffff, ffffffff, ffffffff, ffffffff
# gcc -O2 -Wall -o test test.c
# ./test
test = 00000000, 00000000, 00000000, ffffffff
# gcc -O1 -Wall -o test test.c
# ./test
test = ffffffff, ffffffff, ffffffff, ffffffff
# gcc -v
使用内建 specs。
目标:i686-pc-linux-gnu
配置为:/var/tmp/portage/sys-devel/gcc-4.3.4/work/gcc-4.3.4/configure --prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.3.4 --includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include --datadir=/usr/share/gcc-data/i686-pc-linux-gnu/4.3.4 --mandir=/usr/share/gcc-data/i686-pc-linux-gnu/4.3.4/man --infodir=/usr/share/gcc-data/i686-pc-linux-gnu/4.3.4/info --with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4 --host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec --disable-fixed-point --enable-nls --without-included-gettext --with-system-zlib --disable-checking --disable-werror --enable-secureplt --disable-multilib --enable-libmudflap --disable-libssp --enable-libgomp --disable-libgcj --with-arch=i686 --enable-languages=c,c++,treelang --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.3.4 p1.0, pie-10.1.5'
线程模型:posix
gcc 版本 4.3.4 (Gentoo 4.3.4 p1.0, pie-10.1.5)
编译器的问题?
函数写法问题?
代码如下:test.c
#include <stdio.h>
#include <linux/types.h>
#define UNIT_BITS 32
struct data {
__u32 d3;
__u32 d2;
__u32 d1;
__u32 d0;
};
static inline void
data_set_hard (struct data *ret,
__u32 a, __u32 b, __u32 c, __u32 d)
{
ret->d3 = a;
ret->d2 = b;
ret->d1 = c;
ret->d0 = d;
}
static inline void
data_set (struct data *ret, int bit)
{
__u32 *data[4];
int a, b;
a = bit / UNIT_BITS;
b = bit % UNIT_BITS;
data[0] = &ret->d0;
data[1] = &ret->d1;
data[2] = &ret->d2;
data[3] = &ret->d3;
*data[a] |= 1 << b;
}
int
main (void)
{
struct data test = {0};
int i;
data_set_hard(&test, 0, 0, 0, 0);
for (i=0; i<UNIT_BITS*4; i++) {
data_set(&test, i);
}
printf ("test = %.8x, %.8x, %.8x, %.8x\n",
test.d3, test.d2, test.d1, test.d0);
return 0;
}
|
问题已解决,发现是 gcc 4.2.x 和 4.3.x 的 BUG
详情请见 http://linux.chinaunix.net/bbs/r ... 39&ptid=1146854
[ 本帖最后由 platinum 于 2009-12-2 14:44 编辑 ] |
|