Ulrich Eckhardt wrote:
Chad wrote:
int main(void) {
int a = 0;
if(a == 0) {
fprintf(stderr, "exiting \n");
}
int b = 2;
return 0;
}
--
This will compile with no syntax errors on Suse Linux 9.1 using the gnu
compiler. However, when I try to compile this under FreeBSD 4.8 using
the gnu compiler, I get the following error message:
$gcc -g iffy.c -o iffy
iffy.c: In function `main':
iffy.c:9: syntax error before `int'
Well, how about some exact compiler versions? I'm pretty sure it doesn't
have anything to do with Suse vs FreeBSD but rather with compiler vs
compiler.
Anyhow, I suspect that one of the compilers is C99 aware, while the other
(the one on FreeBSD) is targetting C89. C89 requires that all variables
are declared at the beginning of the block they are used in, which is why
it chokes on the declaration of 'b'.
BTW: never compile without high warning levels (-Wall for gcc), you just
miss too many possible errors.
Uli
Hmmm fascinating. Here is more on what is going on;
Suse Linux 9.1 is running gcc v 3.3.3. When I enable full warnings, I
get:
iffy.c: In function `main':
iffy.c:9: warning: unused variable `b'
FreeBSD 4.8 is running 2.95.3. When I enable full warnings, I still the
the exact same error message:
iffy.c: In function `main':
iffy.c:9: syntax error before `int'
Interesting. Thanks.
Chad