Boost logo

Boost :

From: John Max Skaller (skaller_at_[hidden])
Date: 2001-05-03 12:34:51

Kevin Lynch wrote:

> Apologies for not contributing directly to the discussion, but I must
> ask: why? What was the Committee's reason for only supporting
> initializing integers inline?

> But why isn't there more
> similarity between the floating point built in types and the integer
> built in types in this regard?

It is already possible in C to initialise integers 'inline'
by using an enum. The 'static const int n = const_expr' syntax
adds nothing to the language except verbosity :-)

There is, however, a reason that the syntax is not extended to
floats: there is no such thing as a 'float const expression'.
When you write:

        float x = 1.0/2.0;

the RHS is executed at run time using the target machines floating
point math. The compiler may not have access to this math.
So requiring the RHS to be evaluable at compile time is a huge
impediment to the development of cross compilers.

There is already a requirement that the compiler be able to
create a float in the target machine format. Extending that
to require computations is just too onerous. Unlike integers
and pointers, FP maths can be very tricky :-)

There's no particular reason that a requirement the RHS be a simple
literal couldn't be used. However, very little is gained.
FP math is so expensive that it seems unlikely a variable is much
more expensive.

A short summary: the Committee added a new more C++ like syntax
for creating just those constants that already could be created,
and which are actually useful as constants (for array bounds,
for example).

John (Max) Skaller, mailto:skaller_at_[hidden]
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper
download Interscript

Boost list run by bdawes at, gregod at, cpdaniel at, john at