Casting away const and invariant
Jeff Nowakowski
jeff at dilacero.org
Mon Sep 10 14:47:38 PDT 2007
Janice Caron wrote:
> 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.
And then what happens when you use a new version of the library, where
your assumption is no longer valid? Will the vast majority of libraries
be diligent in specifying const? Is const going to clutter the code
everywhere?
What's the *good* reason that const isn't the default, at least for
function parameters?
-Jeff
More information about the Digitalmars-d
mailing list