This doesn't answer the question "How to detect if printf will support %a?" in the general case, but you can modify your compiler installation so that %a
is supported.
First of all , use mingw-w64. This is an up-to-date fork of MinGW. The original version of MinGW is not well maintained and does not fix bugs such as you are experiencing (preferring to blame Microsoft or something).
Using mingw-w64 4.9.2 in Windows 10, the following code works for me:
#include <stdio.h>
int main()
{
double x = 3.14;
printf("%a\n", x);
}
producing 0x1.91eb85p+1
which is correct. This is still deferring to the Microsoft runtime.
Your question mentions %la
, however %a
and %la
are both the same and can be used to print either a float
or a double
argument.
If you want to print a long double
, then the Microsoft runtime does not support that; gcc and MS use different sizes of long double
. You have to use mingw-w64's own printf implementation:
#define __USE_MINGW_ANSI_STDIO 1
#include <stdio.h>
int main()
{
long double x = 3.14;
printf("%La\n", x);
}
which outputs 0xc.8f5c28f5c28f8p-2
. This is actually the same number as 0x1.91eb85p+1
with more precision and a different placement of the binary point, it is also correct.