4 ms·
Joel's article is a bit long in the tooth. As of C++11, std::string is required to use both a length and a null terminator. With the short string optimization,
by slavik81 5y ago
Joel's article is a bit long in the tooth. As of C++11, std::string is required to use both a length and a null terminator. With the short string optimization, it could even have that exact layout.
> Lazy programmers would do this, and have slow programs
char* str = "*Hello!";
str[0] = strlen(str) - 1;
Modern compilers understand strlen, and will replace the function call with a constant where possible. That code's not slow anymore: https://godbolt.org/z/Kjh8b44Kf https://godbolt.org/z/Kjh8b44Kf
- codesections 5y agoThat's good to know, thanks. But Joel was talking about C rather than C++, where your comments about std::string wouldn't apply, right?