On Wednesday 08 September 2004 12:57, John Lamb wrote:
Steven T. Hatton wrote:
No, I am specifically trying to initialize it at compile time. What the stupid compiler or linker is trying to do is a different story! ;) The code works if I build all the parts in the same compilation unit.
Fair enough, but look at it from the compiler's point of view. If you use a function to initialise a static const and the function is not defined in the same compilation unit, the compiler can't initialise the const at compile time. It's tricker, though I assume it's possible, to design a static linker that could do the additional compilation at link time to assign a value to the const. I think the gnu linker won't do it except, maybe, in simple cases.
I have to confess, I really don't understand all the linkage rules in C++. How is what I'm doing different from using a global static variable? Would that likewise cause problems in similar circumstances?
I wonder if playing around with extern might work?
Did you mean to type "export". I don't think gcc handles export yet, but if you have any success with export (or extern) I'd like to know.
I meant "extern", but I have to confess, I don't know how it might be helpful. I thought it might help if I had a way to explicitly tell the compiler (linker?) that the symbol was external to the translation unit, it might behave differently. -- Regards, Steven