cppsks wrote:
"Bob Hairgrove" <in*****@bigfoot.com> wrote in message
news:vp********************************@4ax.com...
On Fri, 22 Oct 2004 12:06:04 -0500, "cppsks" <sk*****@hotmail.com>
wrote:
I have been working on making a constant array available for the clients.
However, it is placing it in the text segment, and external references
result in unresolved references to the array. Taking the const off the
definition solves the problem (the variable is placed in the data
segment).
Is this how const globals are supposed to work, or did the linker screw
up?
Thanks.
C++ has no meaning for "segments" which are operating-system
dependent.
Did you declare the array with the "extern" keyword and export the
symbol from your executable?
No, the array was declared in the header file as const (originally).
However, there were references to that array in the code and I guess if the
array is in the text segment, you can't refer to that address? I don't
know - that's why I am asking about this on this group. Thanks.
Other than the array being "const" (only readable), what other
"side-effects" are possible when it's const? Does it automatically go in the
text segment? Will there not a symbol generated for it?
Every object declared 'const' has _internal_linkage_ by default. That
[usually] means that there is no way to get to it from another module.
What you have when you put your 'const' in a header is a bunch of those
consts all over the place. If you intend to have a const array of chars
shared between modules, you need to
(a) declare it in the header as such:
extern char const array[];
(b) define it in _one_ of the source files as such:
extern char const array[] = "contents of the shared array";
Then every module that includes the header with the declaration will gain
access to the array defined in one of your source modules.
V