Thoughts on `const' parameters

T. William Wells bill at twwells.uucp
Thu Dec 1 15:31:41 AEST 1988


In article <957 at vsi.COM> friedl at vsi.COM (Stephen J. Friedl) writes:
:      Let's say that I have a function like strchr(), which
: might be written as:
:
:       char *strchr(const char *string, int ch)
:       [function body omitted]
:
:      What prevents me from passing a const argument (say, a string
: in readonly memory), locating my desired character within the string,
: and then storing a NUL there?  Nothing in the declaration prevents
: this, and I've not done anything illegal like playing cast games.

Nothing at all prevents you from doing this, other than your skill as
a programmer.  It's one of the loopholes.  All that the const modifier
says here is that the string isn't modified in the function.

---
Bill
{uunet|novavax}!proxftl!twwells!bill



More information about the Comp.std.c mailing list