🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Can I declare private constants?

#2319
From: Steve Clamage
Date: Fri, 27 Oct 1995 02:27
37 lines
2096 bytes
In article 95Oct26140846@avs.cs.rpi.edu, vandevod@cs.rpi.edu (David Vandevoorde
) writes:
>
>>>>>> "SC" == Steve Clamage <clamage@eng.sun.com> writes:
>[...]
>SC> You can use the enum hack, but it isn't necessary. You can now (if
>SC> your local compiler supports the change) declare a static member of
>SC> any integral type as a manifest constant:
>[...]
>
>Would you happen to know why it must be an ``integral type''?
>I imagine uses for floating-point constants...

I believe it is because integral constant-expressions are a special item
in the language.  A floating-point constant-expression may consist only
of floating-point literals. For example, at file scope:

	const int two = 2; // 'two' is a constant-expression
	int k = two; // OK

	const double pi = 3.1415926535798;
	double x = pi; // error, 'pi' is not a constant-expression

So it seems to me that being able to write
	struct T { static const double e = 2.7182818285; };
doesn't give you any added capability or convenience compared to
	struct T { static const double e; };
because you must still provide a definition someplace.

We might someday revisit the restrictions on floating-point constants,
but it seems to me the rules are at least consistent.
---
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: <46ovik$s80@engnews2.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <VANDEVOD.95Oct26140846@avs.cs.rpi.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 27 Oct 95 02:27:28 GMT
Approved: fjh@cs.mu.oz.au
From: clamage@Eng.Sun.COM (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: Can I declare private constants?
X-Original-Date: 26 Oct 1995 21:45:56 GMT
Organization: Sun Microsystems Inc.
Message-ID: <46ovik$s80@engnews2.Eng.Sun.COM>
References: <VANDEVOD.95Oct26140846@avs.cs.rpi.edu>
Reply-To: clamage@Eng.Sun.COM
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMJBDneEDnX0m9pzZAQF6/gF/TjZ3b5gV9h3wtLQT4B8BNeCvBnbvRP3q
 67LLSM8abdHNARFforvHb0mIn0ij0qAx
 =61ec