[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: static const int optimization fails in conditional expressions



On Tue, Dec 11, 2001 at 08:45:40PM -0600, James E Jurach Jr. wrote:
> I understood from nm(1) output that, at least in the past, g++ did not
> create a symbol for these int's, but rather performed some kind of inline
> optimization.

Compilers are allowed to optimize static const integral members, in the
sense that their values may be used directly.  That has nothing to do with
the requirement that static members must still be defined.

> I don't have access to the specifications, but I was pretty sure that
> developers were allowed to initialize const static members in class
> declarations.  Through google, I find the following statements:

Yes, it's perfectly legal.  But a definition is still required.  This new
rule allows you to move the initialization of the variable from the
definition (outside the class) to the declaration (inside the class).

That has nothing to do with the requirement that static members must still
be defined.


> The following code compiles cleanly:

But you haven't tried to link it yet, have you?  The program isn't done
until the linker's finished.  :-)

> nm(1) output for condexpr.o shows that a symbol "_3Foo.foo" was expected to
> be defined in the object file.  No such symbol appears in testexpr.o.

Which means you still need to define it.


Phil

-- 
If ye love wealth greater than liberty, the tranquility of servitude greater
than the animating contest for freedom, go home and leave us in peace.  We seek
not your counsel, nor your arms.  Crouch down and lick the hand that feeds you;
and may posterity forget that ye were our countrymen.            - Samuel Adams



Reply to: