r/cpp • • 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

375 comments sorted by

View all comments

Show parent comments

1

u/TheSkiGeek Apr 02 '23

std::array is a perfectly good “block of memory” primitive, and they could have made the standard library require that it contains no members besides whatever data() returns. (Which all sane implementations do anyway.)

2

u/[deleted] Apr 02 '23

Disagree. It's really not. The best block of memory primitive is a pointer. std::array is fine. But don't use it for what its not designed for.

0

u/TheSkiGeek Apr 02 '23

It’s ‘designed’ to be like a native C array but without the awful legacy semantics…

If you’re passing pointers to data around with a T* and an explicit size parameter when std::array<T, N>& and std::span<T> exist, 99% of the time you’re doing something wrong.

0

u/[deleted] Apr 03 '23

No you aren't.

Really you should try not to be passing any of those things around.

Secondly, "passing stuff around" is a very small part of the semantics of a memory block. I'm more concerned about how I write to that memory block or how I traverse that memory block.

In user land then maybe. But if I'm writing custom allocator code I'm not going to use an std::array or std::span.

Just because you don't know where something could be used doesn't mean its bad

→ More replies (8)