Christian Kandeler <ch****************@hob.de_invalid> writes:
ni***********@yahoo.com wrote:
Even though your variable is defined in only one header say 'a.h', the
header might get included multiple times (via another header which
includes 'a.h'). To avoid this situation, write some preprocessing
definitions at beginning of the header like:
#ifndef a_h
<your variable declarations>
#endif
#define a_h
This will solve the problem of multiple definitions
No, it will not. Include guards prevent including the same header twice in a
particular source file, which wasn't the OP's problem.
Right.
Type definitions and external function and variable declarations (not
definitions) can be defined in a header, protected by include guards,
because they need to occur exactly once in each translation unit.
They exist for the benefit of the compiler.
Variable and function definitions need to be defined in non-header
source files (*.c files) because they need to occur exactly once in
each program, which may consist of multiple translation units. They
exist for the benefit of the linker, so include guards to not suffice
to restrict them to a single occurrence.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.