Bug 3999 and 4261

Rainer Deyke rainerd at eldwood.com
Wed Sep 1 01:06:51 PDT 2010


On 8/31/2010 19:46, bearophile wrote:
> But you can use const for constants that are known at run-time only.
> While you can't use enum for constant known at run-time.

In C++, const is used for both run-time and compile-time constants.  In
practice, this works out fine.  It its value can only be known at
run-time, it's a run-time constant.  If its value is used at
compile-time, it's a compile-time constant.  If both of these apply,
it's an error.  If neither applies, nobody cares if it's a compile-time
or run-time constant.

(The actual rules in C++ are a bit more complex, less intuitive, and
less useful than that, which is presumably why Walter chose not to copy
the C++ in this case.  Still, overloading 'const' for both compile-time
and run-time constants is viable, and more intuitive than the current
situation with 'enum'.)


-- 
Rainer Deyke - rainerd at eldwood.com


More information about the Digitalmars-d mailing list