Casting away const and invariant

Janice Caron caron800 at googlemail.com
Sun Sep 9 14:12:38 PDT 2007


> It may well be necessary; if it is, the behaviour must be defined
> so that it _works_.

No, it's undefined for a reason. It should stay undefined.

Circumvention is necessary so that you can call library functions
which are incorrectly declared. For example, if a library function is
declared as

int strlen(char[] s); /* erroneous declaration - function does not
modify the bytes of s */

then circumventing the normal casting rules would be harmless, because
no undefined behaviour is being invoked. The key point here is that
you would have to /know/, with absolute certainty, that strlen() was
not going to modify the bytes of your string. If you made the wrong
call ... well, then that's when the undefined behaviour would kick in.

No, Walter is absolutely right to make it undefined. And also
absolutely right to allow circumvention.

My only argument is that circumvention should require a different syntax.



More information about the Digitalmars-d mailing list