I just wrote and ran following program. This just gave an unexpected output without +
sign printed to U...MAX
.
#include <limists.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
// ...
printf("LLONG_MIN: %+lli\n", LLONG_MIN);
printf("LLONG_MAX: %+lld\n", LLONG_MAX);
printf("ULLONG_MAX: %+llu\n", ULLONG_MAX);
return EXIT_SUCCESS;
}
And I got this:
CHAR_BIT: 8
SCHAR_MIN: -128
SCHAR_MAX: +127
UCHAR_MAX: 255
SHRT_MIN: -32768
SHRT_MAX: +32767
USHRT_MAX: 65535
INT_MIN: -2147483648
INT_MAX: +2147483647
UINT_MAX: 4294967295
LONG_MIN: -2147483648
LONG_MAX: +2147483647
ULONG_MAX: 4294967295
LLONG_MIN: -9223372036854775808
LLONG_MAX: +9223372036854775807
ULLONG_MAX: 18446744073709551615
Why is there no +
sign printed for U..._MAX
?
How can I do that?
printf("ULLONG_MAX: +%llu\n", ULLONG_MAX);
? The number is always positive so you can just unconditionally print+
if that is really what you want. – Fatsou
format specifiers allow you to print the sign (e.g. here, while ford
andi
the representation ` [-]dddd` is shown, foru
it's only ` dddd`). – Sopheywarning: '+' flag used with ‘%u’ gnu_printf format [-Wformat=]
– Rudich