"ulrich" <> wrote in message
news

psoswgqxan2mgp5@innsbruck-neu...
> On 5 Apr 2005 23:30:41 -0700, Rajan <> wrote:
> well, if you have
> const int A = 10;
> it will occupy sizeof(int) bytes of memory as long as it lives.
I doubt it, at least for processors that can more efficiently embed
hard-wired immediate values in code than fetch a value from memory.
Examples:
------------
#define A 10
void f(int);
void g()
{
f(A);
}
x86 code generated for g() by VC++ 6.0:
push 10
call f
add esp, 4
------------
const int A = 10;
void f(int);
void g()
{
f(A);
}
x86 code generated for g() by VC++ 6.0:
push 10
call f
add esp, 4
------------
> on the other hand, if you have
> #define A 10
> the _preprocessor_ will literally replace every "A" in your source code by
> "10", so this #defined a uses no memory. however, those variables holding
> the value A use memory, off course.
>
> remark:
> to really avaoid hardcoding of constants (my point of view is that
> "hardcoded" is anything the change of which requires a re-compilation),
> your program should use an initialisation file. then, the name of this
> file is the only thing which needs to be hardcoded.
>
> or even better: pass that name as (the only) command line parameter, or
> read it from the registry. then your program will be totally free of
> hardcoding.
DW