|
Boost : |
Subject: Re: [boost] Formal review request: static size matrix/vector linear algebra library (Boost) LA
From: Jeffrey Hellrung (jhellrung_at_[hidden])
Date: 2010-02-05 13:29:20
Simonson, Lucanus J wrote:
> Jeffrey Bosboom wrote:
>> DE wrote:
>>> looking at traits class specialization i have a question:
>>> is there a reason defining integral constants as following?
>>>
>>> static cont int dim = 42;
>>>
>>> i mean if you do not take address of that member a better solution
>>> (imho) is to define an anonymous enum like
>>>
>>> enum {
>>> dim = 42
>>> };
>>>
>>> or in one line
>>>
>>> enum { dim = 42 };
>>>
>>> rather than defining a global object
>>>
>> An optimizing compiler will perform constant propagation, substituting
>> the value of the variable (in this case, 42) everywhere it is used.
>> If
>> the address of the variable is never taken, the compiler need not
>> actually have a memory location to hold it.
>
> I've had bad experience with optimizing compilers failing to perform constant propagation for static const int the way I expected and prefer enum to avoid such problems. I avoid all static declarations when possible.
>
> Regards,
> Luke
FWIW, I've never had a problem with "static const int" (MSVC8 and 9, GCC
4.3 and 4.4), but if you're worried, there is a boost macro for this:
- Jeff
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk