Const on the call site?

Walter Bright newshound1 at digitalmars.com
Wed Nov 14 10:47:27 PST 2007


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.



More information about the Digitalmars-d mailing list