String literals

Have type const char [] in C++, but are, as an exception to the general rule, allowed to convert to type char * (though deprecated).

Have type char [] in C (even in C99 which has introduced the const keyword), but it is undefined behavior to modify them. (The standard explicitly allows storing them in read-only memory, and overlapping identical string literals.)

It seems to me that it is also possible to modify the C standard to align with C++ without altering the behavior of any existing C code. (On the other hand, we cannot modify the C++ definition of the type of string literals without affecting existing codes.)


Related posts:

  1. std::hash<std::string>
  2. Rvalue reference
  3. GCC #pragma pack bug
  4. Every C programmer should learn some assembly
  5. wprintf(“%s”,…)

Tags:

Leave a Reply

*

Hint: Register at Gravatar and your comments will be accompanied by your personalized icon.