const debacle
Walter Bright
newshound1 at digitalmars.com
Sun Mar 23 03:44:07 PDT 2008
Janice Caron wrote:
> It /doesn't/ modify the input,
By returning the input as a modifiable aggregate, it breaks its promise
not to modify it. The cast to remove const-ness is where the problem is.
Consider again:
T[] f(const T[]);
void g(T[]);
...
T[] t;
g(f(t));
... (*) ...
Let's say g() modifies its argument. Then, at point (*), t has changed,
even though t was passed to a function that promised not to mutate it.
This is fundamentally a broken program.
More information about the Digitalmars-d
mailing list