Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-01-27 09:19:39

Daniel Krügler <dsp_at_[hidden]> writes:

> - Assumption one: Boost does not provide the definitions of
> potential static constants hidden by the BOOST_STATIC_CONSTANT
> definition (I used only the headers of the library, so my potential
> testing bug would be that I had to include the corresponding
> translation units of boost providing the constant's definitions,
> but sorry - I did not find them!).

In general BOOST_STATIC_CONSTANT is used within templates, so the
definition of a corresponding member may be given in the header file:

template <int N>
struct int_
    BOOST_STATIC_CONSTANT(int, value = N);

template <int N>
int const int_<N>::value;

> As I said: If this assumption is false, please blame me straight
> for incomplete testing and for trying to spread bad rumors on this
> (really!) great library.

It's probably not false in most cases.

> - Assumption two: Even if Boost does provide these definitions,
> there may occur problems due to the VC7.1 flags /Za and /Ze (aka
> disabling and enabling language extensions), which I will explain
> in the following. The same point applies as to assumptions one, if
> I did incomplete testing or testing with rather old boost libraries.
> The nasty thing concerning the /Ze flag is that it effectively does
> not "extend" the language in every case. A small testing case is the
> following program:
> a.h: -------------------------
> #ifndef A_H_INC
> #define A_H_INC
> struct A
> {
> static const int val = 42; // Declaration of a static member variable
> };
> #endif
> -------------------------
> a.cpp --------------------
> #include "a.h"
> const int A::val; // Definition might be needed, if the program accesses
> // the adress of A::val
> -------------------------
> main.cpp --------------------
> #include "a.h"
> int main()
> {
> }
> -------------------------
> Although this is a C++ Standard compliant program, it will not
> successfully link with the /Ze flag enabled, which is to my opion a
> real compiler bug (which I already posted to m.p.v.language, but got
> no reasonable response yet). The obtained error message is:
> error LNK2005: "private: static int const A::val" (?val_at_A@@0HB) already
> defined in a.obj
> error LNK2005: "private: static int const A::val" (?val_at_A@@0HB) already
> defined in main.obj

Looks like a bug to me.

> Question: Is this special deficiency of the VC7.1 compiler taken
> account in the current boost library?

I doubt it. How would we do that?

> I think, it is impossible to demand, that users are enforced to use
> either only /Ze or only /Za, because each of these choices has some
> considerable drawbacks (at least on Windows systems...)

Well, it seems to me that we can only respond to actual problems. Do
you have an actual case of using a Boost library where these issues
cause you trouble?

Dave Abrahams
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at