Mail Archives: djgpp/1994/08/19/10:39:18
Why you get duplicate names in multiple C translation units that use the
same header file and include variable definitions:
It's the way C works. You have declarations and definitions. In your
library code, you should have definitions (I think), where you declare
what type of variable it is AND reserve space for it in the data
segment. In your code that uses the library, you only want to declare
the variables, so the compiler knows what type they are and how much
space they take up, but you don't want to actually reserve space for them
in the data segment.
To do this, make "regular" definitions in your library code, like so:
int test;
and make external declarations in your code that uses the library:
extern int test;
Right now, it looks like you are defining the variables in both places,
asking the compiler to create two spaces in the data segment for the same
name -- a duplicate definition.
NOTE: I may have gotten definition and declaration backwards, but the
concept is the same. Hope this helps.
Fred Reimer
+-------------------------------------------------------------+
| The views expressed in the above are solely my own, and are |
| not necessarily the views of my employer. Have a nice day! |
| PGP2.6 public key available via `finger fwreimer AT crl DOT com` |
+-------------------------------------------------------------+
- Raw text -