Re: Duplicate Header Declaration



mdh <mdeh@xxxxxxxxxxx> writes:
On Jul 21, 2:06 am, Lee <l...@xxxxxxxxx> wrote:
mdh wrote:

Amazingly I faced a similar issue only yesterday .

.Then on compiling
kaboom! I have some 68 errors and warnings very similar to those you
got.


Well...I think I finally figured it out completely. It was a
combination of defining a function twice, but also of omitting a ";"
in the header file.

This header file:

void reverse( char *s);
[6 lines deleted]
double a_tof (char *s) <<<<<<<<<=========
[8 lines deleted]
int str_len( char *s);


produces these errors.

error: syntax error before '{' token
: error: redefinition of parameter 'str_len'
error: previous definition of 'str_len' was here
error: syntax error before '{' token
: error: parameter 't' is initialized
[25 lines deleted]
Build failed (27 errors)


Adding one semicolon, clears up all.

The only clue I can see ( probably more readily seen by the more
experienced members) is the first error which occurs here.
[...]

Right. Some compilers will attempt to recover from a syntax error and
continue compilation, in the hope of finding and diagnosing more
errors. But the syntax of C is such that this attempt can easily
fail. If the compiler had correctly guessed that inserting a
semicolon is the right fix, then it could have done so internally and
continued compilation (finally rejecting the translation unit because
of the syntax error). But in this case, it apparently didn't "think"
of that. It likely assumed that the function prototype was the
beginning of a function definition, which it could have been.

The lesson: If your compiler reports a syntax error, fix the *first*
syntax error that it reports (which might be several lines before the
indicated line), and don't take any other error messages too
seriously.

Note that I'm talking specifically about *syntax* errors, constructs
that violate the language grammar. Things like an undeclared
identifier, a misspelled identifier, or a type mismatch usually aren't
syntax errors, and don't cause this kind of havoc. On the other hand,
a misspelled typedef name can act just like a syntax error.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: Negative lookahead regex clarification needed
    ... Every regex engine in existence ... Processing on-the-fly and compilation don't exclude one another. ... > within the text, you don't have a correct statement. ... If the regex engine cannot translate your string, it's a syntax error. ...
    (comp.lang.perl.misc)
  • Re: Compilation errors in Standard header files
    ... >errors in standard header files supplied by VC++ like stdlib.h, ... >When I write a simple C file, its not giving these compilation erros. ... >C2226: syntax error: unexpected type 'T' ... >C2062: type 'const int' unexpected ...
    (microsoft.public.vc.language)
  • Re: why does catching errors that arent thrown give syntax errors?
    ... as appropriate as giving a syntax error for "if ". ... The Java language was designed that way. ... early return, leaving unreachable code after it, as well as prohibiting ... "conditional compilation" purposes, the actual rules differ. ...
    (comp.lang.java.programmer)
  • strange error!
    ... I came across this error during compilation of my program: ... error: syntax error before "typedef" ... What is strange is that I have not edited the standard library at all ...
    (comp.lang.c)
  • make error: routine / goto label duplicated
    ... Compiler reports three errors, all identical ... but pointing to different lines in the program: ... Syntax error: Routine / Goto label duplicated. ...
    (comp.lang.clarion)