🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3543

'const' in header files

#3543
From: Lars Farm
Date: Wed, 28 Feb 1996 18:47
42 lines
2654 bytes
This is a reply to a thread in c.l.c++.moderated. The moderator asked me to
post this in com.std.c++ instead. The thread started with someone
complaining about a warning for an unused variable where he had const float
x = y; in a header.

Experts explained that this is as it should be for const float, but not for
const int (I know that the std does not talk about warnings). The point is:
The experts seems to find some kind of conceptual difference between named
constant floats and named constant ints, such that declaring const int K =
L; in a header is considered good practice but const float X = Y; in a
header is not and justifies a warning. I don't think there should be any
such difference.

In article <4ghtue$e1m@netlab.cs.rpi.edu>,
orfanos@enst.enst.fr (Dimitri Papadopoulos) wrote:

>Also, do you mean that in C++ you can't replace #define by const
>float? I'll have to switch back to #define!

I hope not. I don't get it. Every book (including Stroustrups) urges us to
use const for named constants instead of #define. Linkage for consts is
internal for this reason. Why should a user have to worry about the fact
that a compiler writer implements float and int differently for named
constants? const float can't be considered different from const int, const
short, const long or const any built in type. 

This appears to be a hole in the standard. Maybe it should be tightened a
little bit and require that named constants of built in types shall not be
"instantiated" (directly as inline constants in generated code or as
constant static data) unless actually used. The same kind of requirement is
already in for templates. 


--
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: <AD5A0C5196681CA0D@sleipner.nts.mh.se>
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
From: lars.farm@nts.mh.se (Lars Farm)
Newsgroups: comp.std.c++
Subject: 'const' in header files
Date: 28 Feb 1996 10:47:48 PST
Organization: pv
Approved: austern@isolde.mti.sgi.com
Message-ID: <AD5A0C5196681CA0D@sleipner.nts.mh.se>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: Wed, 28 Feb 1996 13:42:41 +0100
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMTSjpEy4NqrwXLNJAQGMFAH/Ve58Jzwabed7dBsK8flE8REEGH0Gvxns
 qb5LfCn+aVSpd/BSy5Y2WIQNA2BllntMCovQCuMEtYN1EDI5B7G7tQ==
 =NZpy
Originator: austern@isolde.mti.sgi.com