On Sat, 24 Feb 2024 23:54:42 -0000 (UTC), Lawrence D'Oliveiro
<
[email protected]d> wrote:
I think it was Dennis Ritchie who pointed out what a fudge this was:
char *strstr(const char *haystack, const char *needle);
ANSI C introduced the �const� modifier, and wanted to use it for the >arguments to strstr. But if the result is a pointer into the
�haystack� string, then if that is const, then so should the result
be. But that means it can only be assigned to a variable that also has
the �const� modifier.
Really, it should have become two functions, one where both
�haystack� and the result are const, and one where neither is.
It seems to me that the const modifier in this context does not mean
no one can ever modify the string. It is a guarantee that the
function will not modify the string. Once the function returns, all
bets are off.
While I don't recall having the need myself, I see nothing wrong with
calling strstr to find a substring and then doing whatever I want to
the haystack, such as terminating it either before of after the
substring by inserting a '\0'.
--
Remove del for email
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)