q for the C hackers
Jerry Feldman
gaf at blu.org
Tue Aug 19 07:29:21 EDT 2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Mon, 18 Aug 2003 20:53:01 -0400
Ray Cote <rgacote at AppropriateSolutions.com> wrote:
> 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.
The difference, in C, is that the const keyword was introduced by the
ANSI 89 standard. Unlike C++, NUMBER_OF_UNITS (const int) is a variable
and may even be altered. In C++, this construct would be a true constant
(as Aaron mentions).
- --
Jerry Feldman <gaf at blu.org>
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE/QgoR+wA+1cUGHqkRAljfAJ0ZGX2IQ7ogou/wn6BGs7IDdacRlwCfRFUq
zg4UxBnSHaWGHIY+8LLpg3k=
=5VN8
-----END PGP SIGNATURE-----
More information about the gnhlug-discuss
mailing list