PhobosWatch: manifest => enum

Walter Bright newshound1 at digitalmars.com
Fri Dec 28 10:50:17 PST 2007


Jérôme M. Berger wrote:
>>>     BTW, I think it was Janice who suggested that the compiler should
>>> know whether a constant needs to be manifest or not (depending on
>>> whether its address is taken somewhere). This would remove the need
>>> for a way to distinguish manifest constants explicitly. Any thoughts
>>> on that?
>> The reason this won't work is because:
>>     const int x = 3;
>> will type x as const(int), not int. There needs to be a way to declare a
>> constant of type int.
> 
> 	Er, why? Taking "&x" should return a "const (int)*" and using "x"
> directly should always work so long as you don't modify it.

This is where we start to see a problem if we don't type const(int) 
differently from int - we no longer have a straightforward rule of what 
the type of &x is. This may not seem consequential in trivial cases, but 
when you start having more complex generic code, things can get 
maddening. C++ tries to have it both ways, leading to startling 
complexity in the language definition, and a lot of intractable problems 
cropping up in metaprogramming.

> Are you
> telling us that the following code will fail:
> 
> void func (int param)
> {
> }
> 
> const int x = 42;
> int y = x;              // <= This should work
> func (x);               // <= This should work too
> 
> 	Or is there something I'm missing here?

These will both still work.



More information about the Digitalmars-d mailing list