The signature of std::strtol
is formulated as follows:
long strtol(const char *str, char **str_end, int base);
I actually expect the second parameter to be of type const char**
. Any explanation on why it is of type char**
instead? Note that, it is possible to modify a variable of type const char**
. What you cannot modify is a char* const *
variable.
In the days of yore (before C90) C had no concept of const
and everything used plain char*
.
Since char*
can be implicitly converted to a char const*
changing the signature of most library functions to support const
wasn't too much of an issue. char**
however can't be converted to a char const**
, see the following note from the C++ standard for why
Since C doesn't support overloading the committee had to choose between breaking legacy code, or forcing everyone to pass in a char**
. Neither is ideal but it looks like they went with the latter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With