Re: Constant evaluation
- From: Ulrich Eckhardt <eckhardt@xxxxxxxxxxxxxx>
- Date: Wed, 01 Aug 2007 09:18:25 +0200
ZartPARZ wrote:
Could you told me adventage/disadventage of #define and const? (for
numerical constant) Which one I should use?
Macros are evil, see the C++ FAQ at parashift.com.
I have one more question, too, why did you quote this:
"Carl Daniel [VC++ MVP]" wrote:
ZartPARZ wrote:
Hi
If I have a code like
#define mass 2.4
#define g 9.8
double potential(double height)
{
return mass * g * height;
}
My question is the mass*g part will be calculate at compile time or
run-time? And if I use const double mass=2.4 instead, when is it
calculated?
In an optimized (Release) build, the compiler will perform the
calculation of mass*g at compile time regardless of whether you use a
#define or a const double.
-cd
?
Don't top-post, don't full-quote unnecessarily.
Uli
.
- References:
- Re: Constant evaluation
- From: Carl Daniel [VC++ MVP]
- Re: Constant evaluation
- Prev by Date: Re: UCS-2 and UTF-8 conversion
- Next by Date: problem using static libcurl
- Previous by thread: Re: Constant evaluation
- Next by thread: Re: " X *= 0 " should crash my app like " X /= 0 " does.
- Index(es):
Relevant Pages
|