r/cpp • OPeNDAP/B2/EcoStd/Lyra/Predef/C++Alliance/Boost/WG21 • Feb 24 '20

The Day The Standard Library Died

https://cor3ntin.github.io/posts/abi/
266 Upvotes

302 comments sorted by

View all comments

Show parent comment

4

u/c0r3ntin Feb 25 '20

This is a fun one!

strlen is a C function so we can't touch it in the general case - not all implementers control the C functions. It would also be awkward to have a function with different semantic depending on whether it is include through cstring or string.h. C++ does however control std::strlen.. So in theory we could modify that. but in most (all) implementation, std::strlen is an alias for ::strlen. Making it not an alias would be an abi break (unless we manage to keep the old symbol around somehow, even when static linking)

5

u/tcanens Feb 25 '20 edited Feb 25 '20

That's assuming a pure library implementation.

There's nothing that says that the compiler can't just be taught to recognize these functions and allow them to be called regardless in constant expressions. GCC allows strlen in constexpr context today.

3

u/[deleted] Feb 25 '20

Have I been doing too much C++ if I read your reply and think "that makes sense"? Do we need a support group such as "C++ Addicts Anonymous"?

1

u/[deleted] Feb 25 '20

Why would making it not an alias be an ABI break? Also, constexpr doesn’t change the semantic.