Article View: comp.std.c++
Article #3610Re: 'const' in header files
From: Lars Farm
Date: Thu, 07 Mar 1996 15:44
Date: Thu, 07 Mar 1996 15:44
41 lines
2354 bytes
2354 bytes
In article <31379F8F.7659@compuserve.com>,
"John I. Moore, Jr." <70672.1744@compuserve.com> wrote:
>I think that there may be some misunderstanding about what a const data
>member actually represents.
No. I'm not talking about member constants.
>In general, a const defined at file scope can be
>of any type. In C++, it is generally preferable to use const instead of
>#define.
>
> const int maxSize = 100; //preferable to "#define maxSize 100"
Yes and I think this is standard practice. People rely on the fact that
unused constants are optimized away. Unfortunately, it appears that some
compiler writers do this only for the special case of integer types. I see
no reason why this should be any different:
const float F = 1.234; //should be preferable to "#define F 1.234"
Isuggested that required behaviour was that these constants are not
instantiated unless actually used, much like templates. Rather than leaving
it as an optional optimization as it appears to be now. This should apply
to any built in type. Thus invalidating stupid warnings about unused
variables. If some compilers warn about this, and according to the thread
in c.l.c++.moderated some do, then many users will have to revert to the
#define style constants instead. Is that the intent of the language
designers?
--
Lars Farm, lars.farm@nts.mh.se
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID:
<AD64B66E966816216@sleipner.nts.mh.se>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<AD5A0C5196681CA0D@sleipner.nts.mh.se> <31379F8F.7659@compuserve.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: lars.farm@nts.mh.se (Lars Farm) Newsgroups: comp.std.c++ Subject: Re: 'const' in header files Date: 7 Mar 1996 15:44:51 GMT Organization: pv Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <AD64B66E966816216@sleipner.nts.mh.se> References: <AD5A0C5196681CA0D@sleipner.nts.mh.se> <31379F8F.7659@compuserve.com> NNTP-Posting-Host: taumet.eng.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Nntp-Posting-Host: sleipner.nts.mh.se X-Lines: 34 Content-Length: 1346 Originator: clamage@taumet