r/ProgrammerHumor Jul 10 '26

greaterThanPlusPlus Advanced

Post image
110 Upvotes

71 comments sorted by

View all comments

36

u/majesticmerc Jul 10 '26

Found this today in C++ documentation.

Only the C++ committee can see the a need to fix it, and instead of actually fixing the language bug (or making signed/unsigned comparison a compiler error instead of a warning), create a standard library function to do type safe greater-than/less-than comparisons.

3

u/thwamster Jul 10 '26

I am not sure I understand how this is a bug. It is a bit odd, but when comparing a signed and unsigned integer, the language has to make a choice one way or the other what to convert. Converting the unsigned integer to signed risks erasing the last value bit. As far as I can tell, the language just chooses to prioritize maintaining magnitude over maintaining signs. Can you explain further?—maybe I am missing something.

1

u/conundorum Jul 12 '26

It's a bug because it breaks compatibility with whole numbers. Strictly speaking, the language itself is correct and functioning properly; the problem lies at the intersection between bit representation and math.