Hacker News new | past | comments | ask | show | jobs | submit login
Quick case: Char Pointer vs. Char Array in C++ (bfilipek.com)
9 points by signa11 on July 16, 2014 | hide | past | favorite | 4 comments



This 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.


So, you're suggesting that we take a standard language feature and replace it with an implementation-dependent one?


Strange, 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++.


still, it can happen and you get 'unexpected' runtime bug...




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: