SimonX
2006-03-17, 16:08:58
Probiert auf einem P3-800, wie auch auf meinem P4 mit SuSe 10 und gcc 4.0.2:
#include <stdio.h>
typedef struct A A;
struct A {
int no;
A *sub;
};
void main()
{ A sub={0, NULL};
A root={0, &sub};
A *pos=&root;
pos=&pos->sub[pos->no++];
printf("%d %d %p %p %p\n", root.no, sub.no, &root, &sub, pos);
}
<~/test> 55>gcc -O0 -o sadd sadd.c
sadd.c: In function ‘main’:
sadd.c:10: warning: return type of ‘main’ is not ‘int’
<~/test> 56>sadd
0 1 0xbffb7b84 0xbffb7b8c 0xbffb7b8c
<~/test> 57>gcc -v
Using built-in specs.
Target: i586-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-
prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/us
r/lib --libexecdir=/usr/lib --enable-languages=c,c++,objc,f95,java,ada --disable
-checking --with-gxx-include-dir=/usr/include/c++/4.0.2 --enable-java-awt=gtk --
disable-libjava-multilib --with-slibdir=/lib --with-system-zlib --enable-shared
--enable-__cxa_atexit --without-system-libunwind --host=i586-suse-linux
Thread model: posix
gcc version 4.0.2 20050901 (prerelease) (SUSE Linux)
<~/test> 58>
<~/test> 58>/usr/local/gcc-4.1.0/bin/gcc -O0 -o sadd sadd.c
sadd.c: In function ‘main’:
sadd.c:10: warning: return type of ‘main’ is not ‘int’
<~/test> 59>sadd
0 1 0xbf9a4ef0 0xbf9a4ef8 0xbf9a4ef8
<~/test> 60>/usr/local/gcc-4.1.0/bin/gcc -v
Using built-in specs.
Target: i586-suse-linux
Configured with: ../gcc-4.1.0/configure --prefix=/usr/local/gcc-4.1.0 --enable-java-awt=gtk --with-cpu=pentium4 --enable-threads=posix --enable-languages=c,c++,java --disable-checking --host=i586-suse-linux --disable-libjava-multilib --without-system-libunwind --with-system-zlib
Thread model: posix
gcc version 4.1.0
<~/test> 61>
Auf anderen Maschinen mit älteren gcc (gcc3.3.x und gcc3.4.x) gibt es das Problem nicht.
<~/test> >gcc -o sadd sadd.c
sadd.c: In function `main':
sadd.c:10: warning: return type of `main' is not `int'
<~/test> >sadd
1 0 11fffbfe0 11fffbfd0 11fffbfd0
<~/test> >gcc -v
Reading specs from /usr/local/gcc-3.3.1/lib/gcc-lib/alphaev68-dec-osf5.1/3.3.1/specs
Configured with: ../gcc-3.3.1/configure --prefix=/usr/local/gcc-3.3.1 --disable-shared
Thread model: single
gcc version 3.3.1
<~/test> >cc -o sadd sadd.c
<~/test> >sadd
1 0 11fffbfd8 11fffbfe8 11fffbfe8
<~/test> >cc -V
Compaq C V6.4-216 (dtk) on Compaq Tru64 UNIX V5.1A (Rev. 1885)
Compiler Driver V6.4-013 (dtk) cc Driver
<~/test> >
Ich probiere gleich mal den gcc-3.4.6 auf meinem Rechner aus.
Edit
Ach ja, der Bug is das no nicht von root hoch gezählt wird sondern von sub.
#include <stdio.h>
typedef struct A A;
struct A {
int no;
A *sub;
};
void main()
{ A sub={0, NULL};
A root={0, &sub};
A *pos=&root;
pos=&pos->sub[pos->no++];
printf("%d %d %p %p %p\n", root.no, sub.no, &root, &sub, pos);
}
<~/test> 55>gcc -O0 -o sadd sadd.c
sadd.c: In function ‘main’:
sadd.c:10: warning: return type of ‘main’ is not ‘int’
<~/test> 56>sadd
0 1 0xbffb7b84 0xbffb7b8c 0xbffb7b8c
<~/test> 57>gcc -v
Using built-in specs.
Target: i586-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-
prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/us
r/lib --libexecdir=/usr/lib --enable-languages=c,c++,objc,f95,java,ada --disable
-checking --with-gxx-include-dir=/usr/include/c++/4.0.2 --enable-java-awt=gtk --
disable-libjava-multilib --with-slibdir=/lib --with-system-zlib --enable-shared
--enable-__cxa_atexit --without-system-libunwind --host=i586-suse-linux
Thread model: posix
gcc version 4.0.2 20050901 (prerelease) (SUSE Linux)
<~/test> 58>
<~/test> 58>/usr/local/gcc-4.1.0/bin/gcc -O0 -o sadd sadd.c
sadd.c: In function ‘main’:
sadd.c:10: warning: return type of ‘main’ is not ‘int’
<~/test> 59>sadd
0 1 0xbf9a4ef0 0xbf9a4ef8 0xbf9a4ef8
<~/test> 60>/usr/local/gcc-4.1.0/bin/gcc -v
Using built-in specs.
Target: i586-suse-linux
Configured with: ../gcc-4.1.0/configure --prefix=/usr/local/gcc-4.1.0 --enable-java-awt=gtk --with-cpu=pentium4 --enable-threads=posix --enable-languages=c,c++,java --disable-checking --host=i586-suse-linux --disable-libjava-multilib --without-system-libunwind --with-system-zlib
Thread model: posix
gcc version 4.1.0
<~/test> 61>
Auf anderen Maschinen mit älteren gcc (gcc3.3.x und gcc3.4.x) gibt es das Problem nicht.
<~/test> >gcc -o sadd sadd.c
sadd.c: In function `main':
sadd.c:10: warning: return type of `main' is not `int'
<~/test> >sadd
1 0 11fffbfe0 11fffbfd0 11fffbfd0
<~/test> >gcc -v
Reading specs from /usr/local/gcc-3.3.1/lib/gcc-lib/alphaev68-dec-osf5.1/3.3.1/specs
Configured with: ../gcc-3.3.1/configure --prefix=/usr/local/gcc-3.3.1 --disable-shared
Thread model: single
gcc version 3.3.1
<~/test> >cc -o sadd sadd.c
<~/test> >sadd
1 0 11fffbfd8 11fffbfe8 11fffbfe8
<~/test> >cc -V
Compaq C V6.4-216 (dtk) on Compaq Tru64 UNIX V5.1A (Rev. 1885)
Compiler Driver V6.4-013 (dtk) cc Driver
<~/test> >
Ich probiere gleich mal den gcc-3.4.6 auf meinem Rechner aus.
Edit
Ach ja, der Bug is das no nicht von root hoch gezählt wird sondern von sub.