PhobosWatch: manifest => enum
"Jérôme M. Berger"
jeberger at free.fr
Fri Dec 28 06:51:40 PST 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Walter Bright wrote:
> Jérôme M. Berger wrote:
>> Walter Bright wrote:
>
>> the only question is what syntax to use: either
>> a counter-intuitive extension to enums or a new keyword (or a minor
>> extension to the alias keyword as was suggested by somebody).
>
> I found the "use an alias when declaring one constant" and "use an enum
> when declaring more than one constant" to be difficult to justify. It's
> like saying arrays with only one element should not be allowed.
>
I don't think anybody suggested using an enum for declaring more
than one constant. The suggestions were more on the line of:
keyword {
int x = 42;
float y = 42.42;
}
Where "keyword" could be one of "constant", "invariant", "alias" or
anything that means constant (but not "enum", anymore than
"abstract" or "cat": those mean something else).
>
>> 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. 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?
Jerome
- --
+------------------------- Jerome M. BERGER ---------------------+
| mailto:jeberger at free.fr | ICQ: 238062172 |
| http://jeberger.free.fr/ | Jabber: jeberger at jabber.fr |
+---------------------------------+------------------------------+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
iD8DBQFHdQ18d0kWM4JG3k8RAmsFAKCoFDdLY69rxxKh/ByoRR+eKKHtVACfb2lK
u2sdS/cU51nKadzhMs1burc=
=hxW2
-----END PGP SIGNATURE-----
More information about the Digitalmars-d
mailing list