Let's say I want to build a printf-like formatter for various values. However, to catch edge cases at the top of my itoa
function, I would like to do something like this:
char* itoa(int number) {
if (num == INT_MIN)
return INT_MIN_TEXT; // "-2147483648" or whatever it is on that system
// actual code to do itoa...
}
Or, is even doing something getting a string literal of the limits.h
a non-trivial task?
Does a macro have access to the system limits, such as:
// Also should make it 'const' or return a copy.
#define INT_MIN_TEXT ((INT_MIN == -2147483648)? "-2147483648" : "UNKNOWN")