meyering@cs.utexas.edu (Jim Meyering) (02/22/89)
In these 3 cases, if -O is used, we get the right answer. Similarly, if statements like "foo = n*n;" or "printf("%d\n",n);" are placed between the definition and the use of n, the problem does not arise. % gcc -DARGV gcc-bug.c; a.out 1 n=1, n*n=-134219372 % gcc -DLITERAL gcc-bug.c; a.out 1 n=1, n*n=124 % gcc -DCONSTANT gcc-bug.c; a.out 1 n=1, n*n=1 % gcc -v -DARGV gcc-bug.c gcc version 1.33 /p/lib/gcc-1.33/gcc-cpp -v -DARGV -undef -D__GNUC__ -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ gcc-bug.c /tmp/cca25288.cpp GNU CPP version 1.33 /p/lib/gcc-1.33/gcc-cc1 /tmp/cca25288.cpp -quiet -dumpbase gcc-bug.c -version -o /tmp/cca25288.s GNU C version 1.33 (sparc) compiled by GNU C version 1.33. as /tmp/cca25288.s -o gcc-bug.o ld -e start -dc -dp /lib/crt0.o gcc-bug.o /p/lib/gcc-1.33/gcc-gnulib -lc 0.2u 1.0s 0:06 17% 0+272k 86+32io 157pf+0w % ------------------------------------ void main(argc,argv) int argc; char **argv; { int n, atoi(); #if defined(ARGV) if (argc < 2) { printf("usage: %s n\n",argv[0]); exit(1); } n = atoi(argv[1]); #elif defined(LITERAL) n = atoi("1"); #elif defined(CONSTANT) n = 1; #else # error "must use -D(ARGV|LITERAL|CONSTANT)" #endif printf("n=%d, n*n=%d\n", n, n*n); exit(0); } -- --- Jim Meyering meyering@cs.utexas.edu