[
Lists Home |
Date Index |
Thread Index
]
On Sun, 25 Jan 2004 16:01:36 +0000, Daniel James
<daniel.james@mochamail.com> wrote:
>On Sat, 24 Jan 2004 23:23:06 -0800, Jeremy H. Griffith wrote:
>
>> char *strrchr( const char *string, int c );
>
>The const in strrchr (and strchar, strstr, strpbrk etc.) isn't too great:
>
>#include <stdio.h>
>
>int main()
>{
> const char text[] = "Foo";
> *strrchr(text, 'F') = 'B';
> puts(text);
>}
>
>Although that doesn't stop const being useful, just points out a
>problem with the C standard library.
I don't mean to beat this dead horse into the ground, but there
would only be a problem there if you had:
const char *strrchr( const char *string, int c );
But you don't; the return value is *not* const, and that's what
you are using in your assignment. Granted, the return is an
alias for a string declared as const, but to me this is simple
pilot error, nothing wrong with the aircraft... ;-)
-- Jeremy H. Griffith, at Omni Systems Inc.
(jeremy@omsys.com) http://www.omsys.com/
|