Article View: comp.std.c++
Article #2829Re: Can I declare private constants?
From: Ulf Schuenemann
Date: Mon, 04 Dec 1995 22:16
Date: Mon, 04 Dec 1995 22:16
40 lines
2468 bytes
2468 bytes
In article <49lcij$i7h@engnews1.eng.sun.com>, clamage@Eng.Sun.COM (Steve Clamage) writes:
|> Now suppose you declare
|> extern const int x;
|> The first sentence doesn't require an initializer, since x has external
|> linkage. The second sentence just says x must be initialized. It doesn't
|> say it has to be initialized here. In fact, this line of code is a
|> declaration but is not a definition, so the initialization would appear
|> elsewhere.
So you say the term "is initialized" does mean somewhere,
not necessarily here. Then the same holds for "be initialized".
DWP 7.1.5.1 [dcl.type.cv], 2:
Unless explicitly declared extern, a const object
does not have external linkage
and shall be initialized (8.5, 12.1);
^^^^^^^^^^^^^^
... [can call default-ctor] otherwise if the const object
is not initialized with an explicit initializer
^^ ^^^^^^^^^^^
the program is ill-formed.
So "const int x;" is not disallowed by [dcl.type.cv], provided
somewhere it is initialized by some "const int x = 1;" ?
It is _only_ illegal because of the One-Definition-Rule (ODR)
as both are definitions.
Ulf Schuenemann
--------------------------------------------------------------------
,_. Ulf Schuenemann
#, \ Fakultaet fuer Informatik, Technische Universitaet Muenchen, Germany.
| > email: schuenem@informatik.tu-muenchen.de
v=-< WWW: http://hphalle2.informatik.tu-muenchen.de/~schuenem/
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<49v0tq$ap2@sunsystem5.informatik.tu-muenchen.de>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamageReferences:
<49kge5$imb@sunsystem5.informatik.tu-muenchen.de> <49lcij$i7h@engnews1.eng.sun.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage From: schuenem@informatik.tu-muenchen.de (Ulf Schuenemann) Newsgroups: comp.std.c++ Subject: Re: Can I declare private constants? Date: 4 Dec 1995 22:16:22 GMT Organization: Technische Universitaet Muenchen, Germany Sender: USENET Newssystem <news@informatik.tu-muenchen.de> Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <49v0tq$ap2@sunsystem5.informatik.tu-muenchen.de> References: <49kge5$imb@sunsystem5.informatik.tu-muenchen.de> <49lcij$i7h@engnews1.eng.sun.com> NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Nntp-Posting-Host: hpbroy14.informatik.tu-muenchen.de Originator: schuenem@hpbroy14.informatik.tu-muenchen.de Content-Length: 1442 X-Lines: 36 Originator: clamage@taumet