Unexpected exit code for a C program compiled for 32 bit architecture using gcc
问题 I wrote a simple C program and compiled it for 32 bit architecture. But when I ran it, I found unexpected results. #include <stdio.h> int foo(int n) { int sum=0; int i; if (n <= 1 || n >= 0x1000) return n; for (i=0; i<= n; i++) { sum = sum + i; } return foo(sum); } int main(int argc, char** argv) { int n; n = foo(200); printf("\n\n main about to return %d \n\n", n); return n; } ➜ wbench gcc -o test.elf test.c -m32 -fno-stack-protector -mpreferred-stack-boundary=2 -Wall ➜ wbench ./test.elf