3 ms·
Why don't they define a min/max for each primitive type? How many are there, 15?
by peheje 2y ago
Why don't they define a min/max for each primitive type?
How many are there, 15?
- kzrdude 2y agoEven use a macro to define all typed min max macros
- wahern 2y agoThe 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).
- tempfile 2y agoThis 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.