Given the code below:
<<<snip begin>>>
m3vmsa3.rraaupma /tmp > more p1.c p2.c defs.h
#include "defs.h"
int main()
{}
...skipping...
#include "defs.h"
...skipping...
#ifndef DEFS_H
#define DEFS_H
const char* STR1="Hello World";
const int i1=0;
#endif
<<<snip end>>>
If compiled:
m3vmsa3.rraaupma /tmp > aCC p1.c p2.c
p1.c:
p2.c:
/usr/ccs/bin/ld: Duplicate symbol "STR1" in files p1.o and p2.o
/usr/ccs/bin/ld: Found 1 duplicate symbol(s)
What is the best option for STR1: "static const" or "#define"?
Why is "i1" not a duplicate symbol?
Thanks in advance,
Jose Luis.
i1 is a const (by itself). STR1 is not a const, it's a regular pointer
to a const char. Make it
const char* const STR1 = ...
and it will be const.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
> > #include "defs.h"
> > int main()
> > {}
>
> > ...skipping...
> > #endif
> > <<<snip end>>>
> > If compiled:
Alternatively, he could just skip the pointer:
char const STR1[] = "Hello World" ;
Most of the time, this is probably closer to what is actually
wanted.
--
James Kanze (GABI Software) email:james...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34