Mail Archives: djgpp/2001/02/12/07:06:29
Yong-Kwang Goh <ykgoh AT email DOT com> wrote:
> Well, the linker encounters 2 copies of the function definition of the
> function "sqr".
Yes, but the reason for that happening is not what you think it
is. Please note that the line "long sqr(int x);" is *not* a definition
of function "sqr". It's a declaration, instead, and the linker
doesn't care about multiple declarations at all. In fact, it doesn't
even *see* them.
> So the linker is confused when the same function is defined twice. I would
> suggest you edit your "calc.h" as follows:
> -------------------------------
> #ifndef CALC_H <== Add this line
> #define CALC_H <== Add this as well
> /*calc.h*/
> long sqr(int x);
> #endif <== And lastly, don't forget to add this too.
> -------------------------------
These additional lines are useful, indeed, but *not* for solving
multiple definition problems reported by the linker. They're against
multiple definitions of types, which the compiler would complain
about, not the linker.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -