News for hackers. Stuff that matters.
Re:Maximal Min() and Max() by peheje on Thursday August 08, 2024 @02:50PM (#41194910)
Why don't they define a min/max for each primitive type? How many are there, 15?
Re:Maximal Min() and Max() by wahern on Thursday August 08, 2024 @03:33PM (#41195317)
The reason the current macro is so complex is because it supports mixed types while avoiding (failing on) integer promotion bugs. A version supporting arguments of all the same type would be just as trivial as in C++ (albeit relying on GCC extensions like statement expressions).
Re:Maximal Min() and Max() by kzrdude on Thursday August 08, 2024 @03:03PM (#41195037)
Even use a macro to define all typed min max macros
Re:Maximal Min() and Max() by tempfile on Friday August 09, 2024 @12:22PM (#41203256)
This is addressed if you chase down the original kernel mailing list thread (the "flamewar" linked in the article). It was important to Linus that the macro was actually min/max and not min_slong max_uint etc, so that people couldn't "accidentally" use the untyped version. In other words he was trying quite hard to "force" people to use these macros.

If you would then say "why doesn't min/max just implement a switch on each primitive type", I think on some level it does just do that.