When do you use const

Stephen Clamage steve at taumet.com
Tue Feb 5 03:24:12 AEST 1991


paul at tredysvr.Tredydev.Unisys.COM (Paul Siu) writes:

>However, what is the advantage of using const over #define?  Why was the
>reason for its addition to ANSI C.

A lot of good answers were posted to this question, but I didn't see any
mention of scoping.  Macros are not scoped.  They exist from the textual
point of declaration to the end of the compilation, unless #undef'd.  So
an innocent #define buried somewhere in the program (inside a function,
or in a nested include file) can unintentionally affect later code.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list