On Mar 3, 4:30 pm, Lionel B <m...@privacy.netwrote:
[...]
Now one thing you can do is
const int const_arr = [20] = { 2, 3, 6, 11, 18, ... } // you have to
explicitly initialize the array with the 20 elements
As I understood it, the OP explicitly required that the array
elements "... be calculated using an equation", so I suspect
that this would not work for them.
If the equation is known at compile time, it's pretty easy to
write a program which will generate the definition of the array,
with all of its initializers. I do this a lot (although I do
remember having problems with it in one case: the array
contained a couple of million members, and the compiler wouldn't
handle it.)
One technique which might be made to work if the
initialisation function were simple/suitable, would be some
template meta-programming trick, where you get the compiler to
perform the calculation, the canonical example being a
compile-time calculated factorial:
http://en.wikibooks.org/wiki/C%2B%2B...Template_Meta-
Programming#Example:_Compile-time_Factorial
This would be total overkill, though, I suspect.
It's a nice trick for obfuscation, but generating the code with
a separate program is a lot easier and more readable.
--
James Kanze (GABI Software) email:ja*********@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