🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Can I declare private constants?

#2856
From: Steve Clamage
Date: Mon, 04 Dec 1995 23:45
48 lines
2378 bytes
In article ap2@sunsystem5.informatik.tu-muenchen.de, schuenem@informatik.tu-muenchen.de (Ulf Schuenemann) writes:
>
>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".

You are working too hard on this point. Let's assume we are talking
about declarations at file scope.

You can have only one definition for an object, and (by language definition)
initialization occurs (if at all) at the point of definition.

If you write
	const int x;
that is the (one and only) definition, and so it must have an initializer
at this point, if it is going to have one at all, and it must have one.

If you write
	extern const int x;
that is not a definition, and so the one and only definition (somewhere
in this or another translation unit) has the initializer. This line of code
is not a definition because it has external linkage, does not have an
initializer, and does not have a default constructor.

If you write
	extern const int x = 1;
that is a definition. The program cannot contain another definition of this x.
Since x has external linkage, other declarations of it may appear elsewhere.

---
Steve Clamage, stephen.clamage@eng.sun.com




---
[ 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: <49vu1f$nu5@engnews2.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!info.ucla.edu!agate!agate!Matt
References: <49v0tq$ap2@sunsystem5.informatik.tu-muenchen.de>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!info.ucla.edu!agate!agate!Matt
From: clamage@Eng.Sun.COM (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: Can I declare private constants?
Date: 04 Dec 1995 23:45:04 GMT
Organization: Sun Microsystems Inc.
Approved: Matt@Austern
Message-ID: <49vu1f$nu5@engnews2.Eng.Sun.COM>
References: <49v0tq$ap2@sunsystem5.informatik.tu-muenchen.de>
Reply-To: clamage@Eng.Sun.COM
NNTP-Posting-Host: austern.hip.berkeley.edu