RE: C++ static integer class constants...

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

 



> * John Ratliff:
> 
> > On comp.lang.c++, Victor Bazarov says my example program is well-formed
> > standard C++ according to the ISO C++ standard.
> >
> > "Since their address is never taken, the 'foo::A' and 'foo::B' are, in
> > fact, compile-time constant expressions that do not require storage.
> > The objects, therefore, don't need to be defined outside of the class
> > definition.
> 
> This analysis argues from the implementation, not from the standard.
> 
> The standard requires that you provide a definition if you use the
> constant in a place which does not *require* a constant expression.
> In other words,
> 
>   int foo[Class::static_const_member];
> 
> is fine without a definition, but
> 
>   int bar = Class::static_const_member;
> 
> is not.
> 
> It's strange and smells like a mistake in the standard.

In response to my message on comp.lang.c++, Greg Comeau replies

"That's what it says but isn't what it meant.  What it meant is what Victor
said, and hence it was acknowledged as a defect since requiring the
definition in all cases was not the intent when member constants were
allowed."

So, it seems that it is a mistake in the standard. For anyone who doesn't
know him, Greg Comeau is a member of the C++ standards committee.

I think g++ is trying to do the correct thing (according to the intent of
the committee), even in 3.3, but has one problem area. I am going to leave
out my definitions for now since it will compile on both 3.3 and 3.4 now
that I've removed the ternary expression.

--John Ratliff




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux