r/ProgrammerHumor • • 10d ago

Meme cppAndItsVectorBooleans

Post image
3.4k Upvotes

214 comments sorted by

View all comments

Show parent comment

-1

u/JanB1 10d ago

It feels to me that just writing somewhere in some documentation "this is undefined behaviour" is also bad imho, which is one of my biggest grips with C++. So many "undefined behaviour"s that were left that way for "performance", instead of properly addressing/closing them. It's like laying out a minefield for a new programmer, and telling them that the map for the location of the mines is in a hut 300m away from the minefield. And when they step on a mine you scold them and tell them the mine was clearly documented on the map in the hut.

1

u/No-Information-2571 10d ago

What?

No, "undefined behaviour" is a very specific thing, and there's actually not too many of them, and those that are there, have good reasons.

  1. Signed int overflow
  2. Division/modulo by zero
  3. Shift by < 0 or >= type width
  4. Float to int with mismatching type
  5. Null pointer dereference
  6. Out-of-bounds array access
  7. Certain pointer arithmetic
  8. Use after free, double delete
  9. delete mismatch when new/new[]
  10. Delete without virtual destructor
  11. ...

Etc. etc. - and a rather large number you will get warnings in the compiler already. Either way, all of them have tangible reasons.

0

u/vpgel 5d ago

"Actually not too many of them" and yet you outlined at least 10. "Have good reasons" - what reasons?

0

u/No-Information-2571 5d ago

Maybe read the list before asking such a stupid question? Thanks.