define should be the keyword for manifest constants

Bill Baxter dnewsgroup at billbaxter.com
Thu Dec 13 12:43:41 PST 2007


Russell Lewis wrote:
> I thought about suggesting this, but what turned me off to it was this 
> declaration:
> 
>     define int x = some_compile_time_func();
> 
> A C/C++ programmer will probably think of this as a #define-style 
> substitution, which means that he will expect the function to run every 
> time that he uses the constant.  However, what we are trying to declare 
> is a manifest constant.  It seemed like it would introduce confusion.

That may be their first guess as to what it does, but it doesn't seem 
like it would be difficult to relieve oneself of that misconception.

And in any case, the only time the above would work is if 
some_compile_time_function() really is a compile time function.  So it 
doesn't really matter if the user wants to think of it as evaluating 
every time it's used or just once.  That's the whole point of 
compile_time / pure functions.  No side effects and context doesn't matter.

--bb



More information about the Digitalmars-d mailing list