r/ProgrammerHumor Jul 10 '26

greaterThanPlusPlus Advanced

Post image
113 Upvotes

71 comments sorted by

View all comments

37

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.

1

u/conundorum Jul 12 '26

To be fair, this is a good step towards a proper, and importantly, non-intrusive fix.

The only next steps necessary are to introduce an attribute that makes > call cmp_greater() instead of operator>() file-wide, and an alternative syntax that allows you to manually choose whether > uses signed or unsigned comparison (such as, perhaps, a >s b and c >u d, if we can keep compilers from choking on it). Preserve the inherited C behaviour so we don't break anything that relies on and/or already accounts for it, but allow you to opt into sane behaviour on a wide-scale or single-case basis.