const again

Walter Bright newshound1 at digitalmars.com
Sat Dec 8 01:07:26 PST 2007


Sean Kelly wrote:
> It may be stretching the desire to use "macro" too far, but casting 
> could be used to specify the type:
> 
> macro x = 5L; // long int
> macro y = cast(short) 2;
> macro z = "abc"w;

Yes, it could be. But I just can't see it being a preferred choice to use:
	macro y = cast(short) 2;
rather than:
	enum short y = 2;
as the latter is how declarations work (setting aside the use of 'enum' 
for the moment). There is a reasonable school of thought that says that 
the use of casting should be minimized, and that every cast should be 
scrutinized (since it is a meataxe rather than a scalpel). Having too 
many casts in regular use will hide the questionable uses.


> Thus it wouldn't actually be treated like a storage class.  That might 
> also save some confusion for things like:
> 
> enum const static int x = 7;

That wouldn't be allowed any more than:

	typedef static int x = 7;

because it makes no sense.



More information about the Digitalmars-d mailing list