Re: Duplicate Header Declaration
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Mon, 21 Jul 2008 21:52:13 -0700
mdh <mdeh@xxxxxxxxxxx> writes:
On Jul 21, 2:06 am, Lee <l...@xxxxxxxxx> wrote:[6 lines deleted]
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);
double a_tof (char *s) <<<<<<<<<=========[8 lines deleted]
int str_len( char *s);[25 lines deleted]
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
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"
.
- Follow-Ups:
- Re: Duplicate Header Declaration
- From: mdh
- Re: Duplicate Header Declaration
- References:
- Duplicate Header Declaration
- From: mdh
- Re: Duplicate Header Declaration
- From: Lee
- Re: Duplicate Header Declaration
- From: mdh
- Duplicate Header Declaration
- Prev by Date: Re: C and NULL character
- Next by Date: Re: (unsigned)-INT_MIN
- Previous by thread: Re: Duplicate Header Declaration
- Next by thread: Re: Duplicate Header Declaration
- Index(es):
Relevant Pages
|