3 ms·
strchr() is one of several C library functions that have this issue. C++ solved this by overloading strchr(): const char *strchr(const char *s, int c);
by _kst_ 6y ago
strchr() is one of several C library functions that have this issue.
C++ solved this by overloading strchr():
const char *strchr(const char *s, int c);
char *strchr(*char *s, int c);
C of course doesn't have overloading.
One solution could have been to define two functions with different names, perhaps "strchr" and "strcchr". The time to do that would have been 1989, when the original ANSI C standard was published.
I suppose a future C standard could leave strchr() as it is (necessary to avoid breaking existing code) and add two new functions.