On Fri, 18 Jan 2008 08:38:37 -0800 (PST), PlayDough <pladow@gmail.com>
wrote in comp.lang.c++:
Quote:
I finally figured out the proper search terms so that I could find the
answer to this question.
>
Now I understand that const symbols, by default, have internal
linkage, unlike C. And apparently, g++ was broken prior to 4.1.1.
Not broken, just omitting a permissible, but not required,
optimization.
Since it has internal linkage, it can only be referred to in the
current translation unit. Other translation units could refer to the
char array if code in the current TU passed or returned a pointer to
the start or some other member of the array, but to do this there
would need to be an expression that referenced the array name to
create such a pointer.
If the compiler sees that the current TU does not reference an object
with internal linkage, including a reference to create a pointer to
it, it knows that the array cannot actually be accessed by the program
at all.
Some C compilers will do the same thing if the const char array is
defined with the static keyword as well.
Quote:
Sorry to clutter things.
No problem, it is one of the decisions that creates a relatively
silent change from C in C++. Some regard it as an unfortunate choice,
others agree like it.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html