String literals
By chys on July 5th, 2009Have 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:
- std::hash<std::string>
- Rvalue reference
- GCC #pragma pack bug
- Every C programmer should learn some assembly
- wprintf(“%s”,…)
Tags: C/C++
Leave a Reply
Hint: Register at Gravatar and your comments will be accompanied by your personalized icon.
