Manifest constants (was const again)

Janice Caron caron800 at googlemail.com
Fri Dec 7 00:18:24 PST 2007


On Dec 7, 2007 5:08 AM, Walter Bright <newshound1 at digitalmars.com> wrote:
> mandel wrote:
> > I think enums shouldn't be misused for
> > compile time constants.
>
> But they already are used that way.

Indeed they are. I use them that way all the time myself. If I want a
compile time constant, I'll write

    enum { ONE = 1 }

rather than

    static const int ONE = 1;

every time. Obviously I'm going to applaud a more concise syntax, so
long as it's not confusing. Removing the requirement of curly braces
does seem kinda logical.

That said, I'm now wondering if traditional enums arel likely to get
beefed up to the new standard. As in, will we be able to do

    enum MyReal : real { PI=3.14159265358979, E=2.71828182845905 }
    MyReal r;

It doesn't matter if not. I'm just asking.



More information about the Digitalmars-d mailing list