macros: type save, or what?

0ffh spam at frankhirsch.net
Tue Sep 11 12:49:49 PDT 2007


Janice Caron wrote:
> But if macro becomes the "official" way to declare constants then you
> don't get the option to specify the type, because "macro int x = 42;"
> won't compile.

I wonder if this might work? I admit it looks rather ugly, though...

macro defconst(T,name,value)
{
   macro name (cast(T)value);
}

void main()
{
   defconst(int,x,5);
}

> True. I /like/ macros. They can be used for complex and powerful
> abstractions. But if all you want to do is declare a constant, they're
> overkill. They're not the right tool for the job.

If you say it just doesn't feel right for you, I can understand that!

I also like to make use of my freedom to be irrational... ;-)

Regards, Frank



More information about the Digitalmars-d mailing list