For most code either C's macros or C++'s std::numeric_limits
work fine. In C++03 there was an issue that the min()
and max()
members couldn't yield constant expressions but this problem is solved with C++11's constexpr
.
Both approaches are fully type safe and I would be surprised if you could measure a difference between two versions of a program differing only in the way the type properties are obtained. The primary area where macros are not an alternative are templates: you need a fixed names for the templates entities and the macros just don't work like that (they are also expanded at the wrong time during compilation).
Personally, I always use std::numeric_limits<T>
, mainly because I can use it in all of my code and I can remember the names better.