Re: extern const variable in case label
On Oct 3, 7:49 am, "Christian Meier" <chris@no_spam.com> wrote:
"James Kanze" <james.ka...@gmail.com> wrote:
With my compiler and linker I have these symbols over 10
000 times in my executable and I was able to reduce the
program size a bit with changing these constants to extern
which are not used in case labels.
That is strange. I've yet to see a compiler where they'd
take any space at all, as long as their address wasn't
taken.
Eventually my assumption was wrong about the more than 10 000
symbols for this variable.... And I have not checked whether
the address is taken.
<Offtopic: UNIX Commands and Compiler version>
But the command "nm MyExecutable | grep iValue | wc -l" has
the output "11059" at this moment.
We use GCC 4.1.0...
</Offtopic>
Interesting. I would have thought 0 occurances (or at most,
only for those where the address was being taken). It's
possible that in debug mode, g++ would generate them, since you
could presumable modify the value with a debugger, but a quick
check with a single module on my system (g++ 4.1.0 under Solaris
and Linux) didn't reveal them. Even in debug mode: "nm a.out |
grep staticConst" (where the actual variable was named
staticConst) didn't have any output. Sun CC did generate the
object in debug mode (as a global, no less, but with a funny
prefix added to the name, presumably to make it distinct), but
not when optimizing was turned on.
I'm curious. If you compile the following program:
static int const staticConst = 42 ;
int
main()
{
return staticConst ;
}
then do "nm a.out | grep staticConst", what do you get (with and
without optimizing)?
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34