Lies in education [was Re: The "loop and a half"]
On Thu, Oct 12, 2017 at 8:20 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Chris Angelico <rosuav at gmail.com>:
>> On Thu, Oct 12, 2017 at 6:22 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>>> Additionally, you can launder any constant string into a nonconstant
>>> string with strstr(3):
>>> const char *cs = "hello";
>>> char *s = strstr(cs, "");
>>> s = 'y';
>> Well hey, if you want that, you can just cast the pointer.
> Point is, there is no legitimate way to implement the strstr(3)
> prototype. Somebody must be lying through their teeth.
> The idea of "const" (and other type declaration paraphernalia) is to
> prevent accidental bugs at compile time. The noble idea of "const" has
> been undermined by its sloppy use by the standard libraries and the
> language itself.
> BTW, C++ tries to be a bit stricter about "const". It declares two
> separate prototypes:
> const char *strstr(const char *, const char *);
> char *strstr(char *, const char *);
> <URL: http://www.cplusplus.com/reference/cstring/strstr/>
> Also, in C++, string literals are "const char *".
So basically, C++ fixed some problems in C, in the same way that
Python 3 fixed some problems in Python 2. Yet for some reason Python 3
is killing Python, but C++ isn't killing C. Not sure how that works.