www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Const on the call site?

Walter Bright Wrote:

 Robert Fraser wrote:
 What about requiring constants be declared on the call site rather
 than at the function declaration? The compiler then checks the
 function and issues an error if the value isn't const. That way,
 library writers wouldn't have to worry at all about const, so only
 the people ho WANTED to use const in their code could. It's not part
 of the interface of a function, but for most functions, it's the
 caller who knows whether or not the data SHOULD be constant, and that
 way the caller can see automatically that a function changes
 something, and find out where.

This comes under the heading of 'interprocedural analysis', and it requires that the compiler have access to all the source for all the functions (in fact, 100% of the source to the entire program). Such makes it impossible to have opaque interfaces or anything that recursively depends on opaque interfaces. This would include anything that calls anything that depends on the C runtime library (or any other C library). The compiler would have to understand every language used for every part of the program.

I never thought of it in that way; indeed, it would be impossible for a compiled language like D. Might make an interesting feature for a scripting language, though.
Nov 14 2007