Do we really need const?

Jascha Wetzel firstname at mainia.de
Tue Sep 18 01:58:35 PDT 2007


Janice Caron wrote:
> Lets let "ref" mean "the function may modify the parameter", and the
> absense of ref mean "the function may not modify the parameter", but
> leave it to the compiler to decide what is the most efficient way to
> pass the data to the function.
> 
> I think this is a neat idea, however it won't work unless the compiler
> can also do const-checking. This is one more optimisation which having
> const allows. (And const-by-default would make it obvious).

we still need a solution to force pass-by-value and pass-by-reference 
for exported functions that are called from non-D code.

 > ...
> would no longer compile, because under the new scheme, "ref" is
> reinterpreted to mean that c is head-const (because C is a class - see
> definitions in previous post). So instead, you'd have to do:
> 
> class C;
> C c;
> f(&c)
> 
> void f(ref C* c)
> {
>     *c = new C();
> }
> 
> Whether or not that would be considered a prohibiting problem, I don't know.

if you define ref to mean "be able to change the cell the symbol 
represents", that isn't needed.



More information about the Digitalmars-d mailing list