Topic: static const class data members
Author: wmm@fastdial.net
Date: Mon, 30 Oct 2000 21:25:35 GMT Raw View
In article <8t97sk$ak2$1@nnrp1.deja.com>,
Philip Brabbin <pabrabbin@hotmail.com> wrote:
> Section 9.4.2 of the standard states that "If a static data member is
> of const integral or const enumeration type, its declaration in the
> class definition can specify a constant-initializer which shall be an
> integral constant expression".
>
> I've been discussing with a collegue about why the standard does not
> allow static data members which are of floating point types to specify
> constant initializers, but neither of us can come up with a reason.
> Since the standard is very precise on this point I'm sure there must
> be a good reason. We can't see why extending this to floating point
> types would have been semantically different from defining an inline
> function which returns a constant floating point value.
>
> Can anybody shed some light on this ?
I described this in another thread earlier today. The basic
reason is that integral constant expressions are useful (for
"case" labels, array bounds, etc.) while floating point constant
expressions have no special status.
--
William M. Miller, wmm@fastdial.net
Vignette Corporation (www.vignette.com)
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Tue, 31 Oct 2000 00:55:35 GMT Raw View
In article <8t97sk$ak2$1@nnrp1.deja.com>, Philip Brabbin
<pabrabbin@hotmail.com> writes
>Section 9.4.2 of the standard states that "If a static data member is
>of const integral or const enumeration type, its declaration in the
>class definition can specify a constant-initializer which shall be an
>integral constant expression".
>
>I've been discussing with a collegue about why the standard does not
>allow static data members which are of floating point types to specify
>constant initializers, but neither of us can come up with a reason.
>Since the standard is very precise on this point I'm sure there must
>be a good reason. We can't see why extending this to floating point
>types would have been semantically different from defining an inline
>function which returns a constant floating point value.
>
>Can anybody shed some light on this ?
Fundamentally allowing in class initialisation of static const of
integer types was a relatively late change to encourage programmers to
avoid hijacking enums where compile time integer constants were needed.
In the context of compile time, integer values and expressions have
special significance not shared by other types.
Francis Glassborow Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: Philip Brabbin <pabrabbin@hotmail.com>
Date: Mon, 30 Oct 2000 19:32:50 GMT Raw View
Section 9.4.2 of the standard states that "If a static data member is
of const integral or const enumeration type, its declaration in the
class definition can specify a constant-initializer which shall be an
integral constant expression".
I've been discussing with a collegue about why the standard does not
allow static data members which are of floating point types to specify
constant initializers, but neither of us can come up with a reason.
Since the standard is very precise on this point I'm sure there must
be a good reason. We can't see why extending this to floating point
types would have been semantically different from defining an inline
function which returns a constant floating point value.
Can anybody shed some light on this ?
Thanks,
- Phil Brabbin
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]