J
John Reye
Hi,
the C library has weird number printing functions:
sprintf(str, "%d", num_signed)
sprintf(str, "%u", num_unsigned)
I've created a nice macro SPRINTNUM(STR, EXPR), that handles this
automatically, e.g. if EXPR is of type unsigned long long, then I
automatically get sprintf(STR, "%llu", NUM)
Is there something similar in one of the c standards?????
For me this has become a vital macro for working with c and debugging
purposes!
Regards,
J.
PS: why is this macro so important for me?? Well... Exercise for the
interested reader: create a macro MAX_RVALUE(EXPR) to generate the
maximum value that EXPR could possibly hold, i.e. typically for 32
bits processors... MAX_RVALUE(int) = 2147483647. Also create
MIN_RVALUE(EXPR)... i.e. for typically 32 bits processors
MIN_RVALUE(1+2) = -2147483648 .
Now one can test MAX_RVALUE and MIN_RVALUE with SPRINTNUM!
the C library has weird number printing functions:
sprintf(str, "%d", num_signed)
sprintf(str, "%u", num_unsigned)
I've created a nice macro SPRINTNUM(STR, EXPR), that handles this
automatically, e.g. if EXPR is of type unsigned long long, then I
automatically get sprintf(STR, "%llu", NUM)
Is there something similar in one of the c standards?????
For me this has become a vital macro for working with c and debugging
purposes!
Regards,
J.
PS: why is this macro so important for me?? Well... Exercise for the
interested reader: create a macro MAX_RVALUE(EXPR) to generate the
maximum value that EXPR could possibly hold, i.e. typically for 32
bits processors... MAX_RVALUE(int) = 2147483647. Also create
MIN_RVALUE(EXPR)... i.e. for typically 32 bits processors
MIN_RVALUE(1+2) = -2147483648 .
Now one can test MAX_RVALUE and MIN_RVALUE with SPRINTNUM!