#define versus const

From: johny smith (princetonharvard_at_charter.net)
Date: 05/29/04


Date: Fri, 28 May 2004 20:08:41 -0600

I have never really understood the difference between

1.) #define NUMBER 1.653

vs.

2.) const double NUMBER = 1.653

I know that the #define is taken care of by the pre-processor and the
compiler is used in the second case but why would one be chosen over the
other.

One book I read suggested that your should prefer the compiler to the
preprocessor, but why does it really matter?

Thanks in advance.



Relevant Pages

  • Re: ISA-independent programming language
    ... the compiler takes care of it. ... >> or two representations for zero should not matter to me. ... Any language is a "CLOSED ENVIRONMENT." ...
    (comp.arch)
  • Re: #define versus const
    ... > I know that the #define is taken care of by the pre-processor and the ... > One book I read suggested that your should prefer the compiler to the ... The value of x is now 17, while with a const it would've been 21. ...
    (comp.lang.cpp)
  • Re: Plz explain me the following code
    ... a Sufficiently Clever Compiler could ... I am saying that I don't care about the order of the calls. ... order were mandated with permission to reorder when it can't matter ... almost any side-effect at all in f or g would prevent re-ordering. ...
    (comp.lang.c)
  • Re: Fortran write(print) problem
    ... * formatting is for when you don't care about the details, this particular case is not even a matter where the compiler might or might not do what you want. ... the standard actually *REQUIRES* the compiler to do what you don't want. ...
    (comp.lang.fortran)
  • Re: How to convert Infix notation to postfix notation
    ... and make all strings const save where the intent ... function whose contract is to change the string. ... the compiler "just" prevents the string ... try to do using the pointer you get. ...
    (comp.lang.c)