Hi all
I am currently playing around with compile time calculations using
template
programming. My idea is to calculate values of some function
int f(int i)
for i from 0 to n and initialize array (global or static member) with
those values.
I want n to also be calculated in compile time.
My solution compiled with GCC 4.2.3 to assembler (g++ -O2 -S) has
code below in static initialization section:
movl $1, _ZN10pow_of_twoILi30EE7values_E
movl $2, _ZN10pow_of_twoILi30EE7values_E+4
...
movl $536870912, _ZN10pow_of_twoILi30EE7values_E+116
movl $1073741824, _ZN10pow_of_twoILi30EE7values_E+120
Is there any way (compiler optimization option maybe) to generate
assembler
code below in .data section instead of above:
_ZN10pow_of_twoILi30EE7values_E:
.long 1
.long 2
...
.long 536870912
.long 1073741824
Such optimization would eliminate some overhead during program startup
and shrink binary file. Gain would not be large, but could be useful
for some
embadded systems.
My other thought was that such optimization would break the
initialization
order. But it shouldn't be a problem, because static array
initialization
works that way.
Cheers
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]