Allocating memory for strings

D

David Thompson

They could have made string literals const while allowing implicit
conversion of const char * to char *,

That would have been much _more_ dangerous; it would allow undetected
screwups even for program(mer)s that went to the effort of using
(adding) the new 'const' qualification. Even if you limited it to
occurring during decay, const char [] to char *, as C++ does.

C++ doesn't actually solve the problem for C strings, and really
can't. What it does do is provide a whole new set of std::*string's,
with lots of new features including correct constificationosity.
and make the return type of
strchr, strstr etc. const char *, as in C++.

No, in C++ there are BOTH const and nonconst versions, overloaded.
Which C++ can easily do because it already needed and had overloading.
C89 didn't, and the committee apparently judged that adding it just
for this would have been overkill. Although a decade later they did
require effective overloading, at least of builtins, for <tgmath.h>.

- formerly david.thompson1 || achar(64) || worldnet.att.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top