const comparison in C and C++
T. William Wells
bill at proxftl.UUCP
Sun Sep 18 20:32:01 AEST 1988
In article <8516 at smoke.ARPA> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
: C "const" basically constrains the means of access, so that for example
: void copy(const char *source, char *destination, unsigned count);
: is a useful declaration for a function that is guaranteed not to alter
: storage via its first parameter. However, assuming this represents a
: block-move function, the destination range is allowed to overlap the
: source range, because modification of any storage validly accessible via
: the second parameter is NOT prohibited.
Sorry Doug, it's undefined. (And, drat, I get to fix a, guess
what, COPY FUNCTION, where I made this same mistake. :-)
>From section 3.5.3:
"If an attempt is made to modify an object defined with a
const-qualified type through use of an lvalue with
non-const-qualified type, the behavior is undefined."
---
Bill
novavax!proxftl!bill
More information about the Comp.lang.c
mailing list