3 ms·
Quick case: Char Pointer vs. Char Array in C++
- kbart 12y agoStrange, never had problems with such constructions. That's quite intuitive actually: first you create a const char array then assign a pointer to it and because this array ("string") is const, any modification is forbidden. That's all - no magic here. In other words, it all boils down to "arrays vs pointers" - a basics of C/C++.
- joebaf 12y agostill, it can happen and you get 'unexpected' runtime bug...
- captainmuon 12y agoThis is one of these unexpected things that make C++ really annoying sometimes. It would have been better to pick just one behavior and use it in both cases. For example, make it mutable (array allocation) in both cases, and if you really need to place the string in the RODATA block (to save memory for repeated immutable strings for example), you could have a compiler directive.
- tobinfricke 12y agoSo, you're suggesting that we take a standard language feature and replace it with an implementation-dependent one?