Callee vs caller const (Was: D - more or less power than C++?)

Georg Wrede georg.wrede at nospam.org
Tue Mar 7 17:07:24 PST 2006


Johan Granberg wrote:

>> 3. read only sematics that work as a strong reminder that one is
>> not suposed to modify somthing (but can be subverted by a cast) 

(Just a thought:)

I wonder if everybody here is thinking like this:

void foo(const int arg)
{
     // whatever
}

void main()
{
     int bar = 3;
     foo(bar);
}

Now, suppose we change the whole thing into:

void foo(int arg)
{
     // whatever
}

void main()
{
     int bar = 3;
     foo(const bar);
}

---

Comments? Ideas?

In non-release code the calling code could inclucde implicit tests for 
variable "sameness", i.e. check that the value is unchanged over the 
function call. That way the callee could simply be unaffected by this 
new twist. Right?

After all, it's the calling code that's interested in "constness", not 
the callee. Or have I missed something?



More information about the Digitalmars-d mailing list