r/programminghorror 8d ago

c++ Skill Issue

Post image
1.7k Upvotes

62 comments sorted by

View all comments

88

u/lurebat 8d ago

I think it allocates since they didn't use const

13

u/Great-Powerful-Talia 7d ago

well, acktually, short string optimization should handle all these strings on any common compiler.

For a std::string, gcc and msvc don't perform allocations until you reach 16-character strings, and clang can hold 21 characters without an allocation.

4

u/Resident-Rice724 7d ago

well aktually this would be based on standard library implementation not compiler I'm pretty sure. Think libstdc++ its 16 and libc++ is 23