[...]
Actually, I recently just blew away my MinGW and reinstalled
everything. In the latest version of GCC (4.6.1), the C99 printf
modifiers appear to work. Not sure what they changed, but it appears
that some workaround has been integrated into the MinGW toolchain.
Interesting. I just did the same thing, and it still doesn't work
correctly.
Under Cygwin, this program:
#include <stdio.h>
int main(void) {
float f = 123.456;
double d = 123.456;
long double ld = 123.456;
printf("float: %d bytes, double: %d bytes, long double: %d bytes\n",
(int)sizeof (float),
(int)sizeof (double),
(int)sizeof (long double));
printf("f = %g\n", f);
printf("d = %g\n", d);
printf("ld = %Lg\n", ld);
return 0;
}
produces this (correct) output:
float: 4 bytes, double: 8 bytes, long double: 12 bytes
f = 123.456
d = 123.456
ld = 123.456
Under MinGW, installed from scratch on Windows 7 just a few minutes
ago,, with gcc 4.6.1, the same program produces this output:
float: 4 bytes, double: 8 bytes, long double: 12 bytes
f = 123.456
d = 123.456
ld = -6.41666e+264
Can you try this program on your system?
I get the same result as you. It seems that their 'long double'
modifier is still broken. Still, I raised an eyebrow when %zu, %td,
%llu, and %lld started working.
\code
#include <stdio.h>
#include <limits.h>
#include <stdint.h>
#include <inttypes.h>
int main( void )
{
printf( "
------------------------------------------------------------------------
\n" );
printf( "| type | specifier | limit |
value |\n" );
printf( "
------------------------------------------------------------------------
\n" );
printf( " %-18s %-9s %-13s %" PRId8 "\n",
"int8_t", PRId8, "INT8_MIN", INT8_MIN );
printf( " %-18s %-9s %-13s %" PRId8 "\n",
"", "", "INT8_MAX", INT8_MAX );
printf( " %-18s %-9s %-13s %" PRId16 "\n",
"int16_t", PRId16, "INT16_MIN", INT16_MIN );
printf( " %-18s %-9s %-13s %" PRId16 "\n",
"", "", "INT16_MAX", INT16_MAX );
printf( " %-18s %-9s %-13s %" PRId32 "\n",
"int32_t", PRId32, "INT32_MIN", INT32_MIN );
printf( " %-18s %-9s %-13s %" PRId32 "\n",
"", "", "INT32_MAX", INT32_MAX );
#if defined(INT64_MIN)
printf( " %-18s %-9s %-13s %" PRId64 "\n",
"int64_t", PRId64, "INT64_MIN", INT64_MIN );
printf( " %-18s %-9s %-13s %" PRId64 "\n",
"", "", "INT64_MAX", INT64_MAX );
#endif
printf( " %-18s %-9s %-13s %" PRIu8 "\n",
"uint8_t", PRIu8, "UINT8_MAX", UINT8_MAX );
printf( " %-18s %-9s %-13s %" PRIu16 "\n",
"uint16_t", PRIu16, "UINT16_MAX", UINT16_MAX );
printf( " %-18s %-9s %-13s %" PRIu32 "\n",
"uint32_t", PRIu32, "UINT32_MAX", UINT32_MAX );
#if defined(UINT64_MAX)
printf( " %-18s %-9s %-13s %" PRIu64 "\n",
"uint64_t", PRIu64, "UINT64_MAX", UINT64_MAX );
#endif
printf( " %-18s %-9s %-13s %" PRIdMAX "\n",
"intmax_t", PRIdMAX, "INTMAX_MIN", INTMAX_MIN );
printf( " %-18s %-9s %-13s %" PRIdMAX "\n",
"", "", "INTMAX_MAX", INTMAX_MAX );
printf( " %-18s %-9s %-13s %" PRIuMAX "\n",
"uintmax_t", PRIuMAX, "UINTMAX_MAX", UINTMAX_MAX );
#if defined(LLONG_MAX)
printf( " %-18s %-9s %-13s %" "lld" "\n",
"long long", "lld", "LLONG_MIN", LLONG_MIN );
printf( " %-18s %-9s %-13s %" "lld" "\n",
"", "", "LLONG_MAX", LLONG_MAX );
printf( " %-18s %-9s %-13s %" "llu" "\n",
"unsigned long long", "llu", "ULLONG_MAX", ULLONG_MAX );
#endif
printf( " %-18s %-9s %-13s %zu\n",
"size_t", "zu", "SIZE_MAX", SIZE_MAX );
printf( " %-18s %-9s %-13s %td\n",
"ptrdiff_t", "td", "PTRDIFF_MIN", PTRDIFF_MIN );
printf( " %-18s %-9s %-13s %td\n",
"", "", "PTRDIFF_MAX", PTRDIFF_MAX );
return 0;
}
\endcode
Before, I would get incorrect results for zu, td, llu and lld. Now
they seem to be working.
------------------------------------------------------------------------
| type | specifier | limit |
value |
------------------------------------------------------------------------
int8_t d INT8_MIN -128
INT8_MAX 127
int16_t d INT16_MIN -32768
INT16_MAX 32767
int32_t d INT32_MIN -2147483648
INT32_MAX 2147483647
int64_t I64d INT64_MIN
-9223372036854775808
INT64_MAX 9223372036854775807
uint8_t u UINT8_MAX 255
uint16_t u UINT16_MAX 65535
uint32_t u UINT32_MAX 4294967295
uint64_t I64u UINT64_MAX
18446744073709551615
intmax_t I64d INTMAX_MIN
-9223372036854775808
INTMAX_MAX 9223372036854775807
uintmax_t I64u UINTMAX_MAX
18446744073709551615
long long lld LLONG_MIN
-9223372036854775808
LLONG_MAX 9223372036854775807
unsigned long long llu ULLONG_MAX
18446744073709551615
size_t zu SIZE_MAX 4294967295
ptrdiff_t td PTRDIFF_MIN -2147483648
PTRDIFF_MAX 2147483647
Best regards,
John D.