Chad wrote:
> I'm not too sure if the question would fall under comp.lang.c or some
> kind of compiler newsgroup. I'm going to ask anyhow.
>
> Given the following:
>
> #include <stdio.h>
>
> 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'
>
> What is going on here?
In "C Classic" all variable declarations in a block had
to appear at the beginning, before any executable statements.
The original 1989 C Standard kept that rule.
The new 1999 C Standard relaxed the rule, allowing you
to intermix declarations and statements in any order you
please (as long as variables are declared before you try to
use them).
It seems you're using two gcc versions, one that obeys
the older declarations-first rule and one that permits the
newer intermixed style. Some gcc versions support both
versions of the Standard, depending on the compile-time
options. Check your gcc versions, and gcc's documentation.
--
Eric Sosman
lid