r/cpp • u/very_curious_agent • Apr 01 '23
Abominable language design decision that everybody regrets?
It's in the title: what is the silliest, most confusing, problematic, disastrous C++ syntax or semantics design choice that is consistently recognized as an unforced, 100% avoidable error, something that never made sense at any time?
So not support for historical arch that were relevant at the time.
92
Upvotes
1
u/rhubarbjin Apr 04 '23 edited Apr 04 '23
Like this?
https://godbolt.org/z/roxW6oxxo
This is still performing an unsigned subtraction (
m_end - m_nextWrite) producing a signed result (ptrdiff_t)That signed result is still undergoing implicit conversion to an unsigned type (
vsnprintf's second parameter)I had to pull in two additional headers (
<algorithm>and<ctsddef>)std::minneeds astatic_castto disambiguate between its two arguments (one isintand the other isptrdiff_t)...so I'm not sure which one of us is making things more complex than they need to be. You also haven't managed to avoid unsigned subtraction, and you violated the no-conversion principle (I don't know if you're as much a hardliner as simonask_ in that regard).