Re: Why do people say 'extern' is error prone ?
"Richard Heathfield" <rjh@see.sig.invalid> wrote in message
news:Ab-dnVw2rd0UyZ3VnZ2dnUVZ8sCknZ2d@bt.com...
> pereges said:
>
>> So far in my code, I haven't used a single static variable or a const
>> variable(I prefer to #defining constants and have them at one place in
>> common.h file) either.
>
> #define has gained a strangely poor reputation amongst some C programmers,
> and one that I don't really understand.
I have a problem with #define, finding it a crude way of defining constants
which you don't want as variables.
And, in a language that frowns on globals, #defines have file scope, so I
can't write:
#define size 1200
int main(void)
{
#define size 300
}
Using const int size=1200 works, but it might generate an unncessary
variable. And it's not that difficult to change these 'constants':
#include <stdio.h>
int main(void){
const double pi=3.142;
double *p=(double*)π
*p=2.71828;
printf("Pi = %f\n",pi);
}
Something in-between is needed! Namely, a true immutable constant with a
proper type and normal scope rules.
> The principal objection seems to
> be that, in a debugger, they are "impossible to read".
>I just tried this in gdb. I don't use gdb a great deal, but I know /how/ to
>use it, so I wrote the following program:
I don't use debuggers either. But I think you're saying that, to examine a
'variable' that the debugger doesnt know, one has to go back to the source
code, work backwards to the definition of that variable, and with luck one
may stumble across a simple #define with that value!
Or it could be an expression involving further #defines buried in a myriad
of include files somewhere.
So yes, I can see the problem.
--
Bart
|