q for the C hackers
Ray Cote
rgacote at AppropriateSolutions.com
Mon Aug 18 20:53:01 EDT 2003
At 8:13 PM -0400 8/18/03, Erik Price wrote:
>However, what is the convention in C? There seem to be two fine
>ways of doing it -- using the preprocessor, or the const keyword:
>
>#define NUMBER_OF_UNITS 8
>
>const int NUMBER_OF_UNITS = 8;
This tends to be the nicer way to do it these days.
Biggest advantage is that you get type checking with a const which
you don't get with a #define.
Been so long since I used pure C (vs C++) compilers, that I'm not
sure whether const ever made it into the C standard, or if it is
still a C++ extension. Well supported, though. Works in all the
compilers I use.
--Ray
--
More information about the gnhlug-discuss
mailing list