Node:parse error at..., Next:undefined reference to..., Previous:Compile-time errors, Up:Compile-time errors
parse error at..., parse error before...
This is a general-purpose syntax error. It is frequently caused by a
missing semicolon. For example, the following code:
#include <stdio.h> /* To shorten example, not using argp */ int main() { printf ("Hello, world!\n") return 0; }
generates the following error:
semicolon.c: In function `main': semicolon.c:6: parse error before `return'
Adding a semicolon (;
) at the end of the line
printf ("Hello, world!")
will get rid of this error.
Notice that the error refers to line 6, but the error is actually on
the previous line. This is quite common. Since C compilers are
lenient about where you place whitespace, the compiler treats line 5
and line 6 as a single line that reads as follows:
printf ("Hello, world!\n") return 0;
Of course this code makes no sense, and that is why the compiler complains.
Often a missing curly bracket will cause one of these errors. For
example, the following code:
#include <stdio.h> /* To shorten example, not using argp */ int main() { if (1==1) { printf ("Hello, world!\n"); return 0; }
generates the following error:
brackets.c: In function `main': brackets.c:11: parse error at end of input
Because there is no closing curly bracket for the if
statement,
the compiler thinks the curly bracket that terminates the main
function actually terminates the if
statement. When it does
not find a curly bracket on line 11 of the program to terminate the
main
function, it complains. One way to avoid this problem is
to type both members of a matching pair of brackets before you fill
them in.