Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Why can't static const float class members be inititalized in the class?

Reply
Thread Tools

Why can't static const float class members be inititalized in the class?

 
 
Martin Rennix
Guest
Posts: n/a
 
      04-17-2007
Eg

class Foo
{
static const float f = 0.0f; // error
static const int i = 0; // ok
};

What's the reasoning behind this seemingly arbitrary limitation?

Martin

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      04-17-2007
Martin Rennix wrote:
> class Foo
> {
> static const float f = 0.0f; // error
> static const int i = 0; // ok
> };
>
> What's the reasoning behind this seemingly arbitrary limitation?


I would guess portability, but don't quote me on that.

Ask in comp.std.c++ -- they hold/discuss the reasoning behind any
decisions that made it to the Standard.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      04-18-2007
Martin Rennix wrote:
> Eg
>
> class Foo
> {
> static const float f = 0.0f; // error
> static const int i = 0; // ok
> };
>
> What's the reasoning behind this seemingly arbitrary limitation?
>
> Martin
>

The compiler is only required to know how to do integer math at compile
time.
 
Reply With Quote
 
Martin Rennix
Guest
Posts: n/a
 
      04-18-2007
On Apr 18, 8:41 am, Ron Natalie <r...@spamcop.net> wrote:
> MartinRennixwrote:
> > Eg

>
> > class Foo
> > {
> > static const float f = 0.0f; // error
> > static const int i = 0; // ok
> > };

>
> > What's the reasoning behind this seemingly arbitrary limitation?

>
> > Martin

>
> The compiler is only required to know how to do integer math at compile
> time.


Is that because in the "olden days" you couldn't guarantee that a FPU
would be available, or the equivalent software floating point library?

 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      04-18-2007
On Apr 18, 5:20 am, Martin Rennix <martin.ren...@gmail.com> wrote:
> On Apr 18, 8:41 am, Ron Natalie <r...@spamcop.net> wrote:


> > MartinRennixwrote:
> > > Eg


> > > class Foo
> > > {
> > > static const float f = 0.0f; // error
> > > static const int i = 0; // ok
> > > };


> > > What's the reasoning behind this seemingly arbitrary limitation?


> > The compiler is only required to know how to do integer math at compile
> > time.


Also, the fact that there is no need for it. It's really a
hack, which was added for integers is because certain uses
require an integral constant expression.

> Is that because in the "olden days" you couldn't guarantee that a FPU
> would be available, or the equivalent software floating point library?


It's because even today, cross-compilers exist, and floating
point results depend on the actual floating point being used.
Something like 2. * 3.14 will have different values on different
machines. And the standard doesn't impose emulation of the
target floating point hardware.

--
James Kanze (GABI Software) email:
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      04-18-2007
Martin Rennix wrote:

>
> Is that because in the "olden days" you couldn't guarantee that a FPU
> would be available, or the equivalent software floating point library?
>

I think it was primarily there for crosscompilers. Integer math is
pretty easy to do universally, floating point is a bit more involved.
Not everybody uses the IEEE fp math.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
float to string to float, with first float == second float Carsten Fuchs C++ 45 10-08-2009 09:47 AM
const vector<A> vs vector<const A> vs const vector<const A> Javier C++ 2 09-04-2007 08:46 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
About static const members appearing in another static const definitions Rakesh Sinha C++ 4 01-13-2005 08:11 AM
Re: float->byte->float is same with original float image. why float->ubyte->float is different??? bd C Programming 0 07-07-2003 12:09 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57