>qazmlp wrote:
Isn't that an advantage of 'const' over '#define' declaration for
constants?
In article <bh*************@news.t-online.com>
Rolf Magnus <ra******@t-online.de> writes:You should always prefer consts over #defines in C++, since there are
other advantages (e.g. they can be used in namespaces and classes) and
no or very few disadvantages.
Yes -- but note that the original question was posted to both
comp.lang.c *and* comp.lang.c++. The "const" keyword has very
different meanings in the two languages (basically, in C++, it
"works right" and does what people expect, while in C, it does
something nobody expects until they mentally substitute "read-only
variable" for the word "const").
The original poster should decide which language he wishes to write
in, and stick with that. It *is* possible to write programs that
are not only syntactically correct, but also even have the same
semantics, in both languages (note that this is harder than it
looks at first). But the result is usually horrible C code and
even worse C++ code. In other words, you can write bad code that
just barely works in both languages, or good code that works only
in one language -- so pick one, and write good code in that language.
--
In-Real-Life: Chris Torek, Wind River Systems (BSD engineering)
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it
http://67.40.109.61/torek/index.html (for the moment)
Reading email is like searching for food in the garbage, thanks to spammers.