0
votes

What is the correct way to avoid warnings on 64bit printf/scanf arguments on the most recent versions of mingw-w64?

I know that mingw-w64 relies on microsoft runtime for many standard library functions, and that these functions are not compatible with C99 standard.

Old answers say to use %I64d, but as the C99 standard is %lld, anyway if I compile with -Wall -pedantic I get warning for BOTH syntax, here is a small example:

#include <stdio.h>

int main(void)
{
    long long test;
    scanf("%I64d", &test);
    scanf("%lld", &test);
}

Compile it with gcc (my version is mingw-w64 5.0.4, gcc 8.2.0):

x86_64-w64-mingw32-gcc -o test.exe test.c -Wall -pedantic

It gives the following warnings:

dev:tmp dev$ x86_64-w64-mingw32-gcc -o test.exe test.c -Wall -pedantic
test.c: In function ‘main’:
test.c:6:11: warning: ISO C does not support the ‘I64’ ms_scanf length modifier [-Wformat=]
     scanf("%I64d", &test);
           ^~~~~~~
test.c:6:11: warning: ISO C does not support the ‘I64’ ms_scanf length modifier [-Wformat=]
test.c:7:14: warning: unknown conversion type character ‘l’ in format [-Wformat=]
     scanf("%lld", &test);
              ^
test.c:7:11: warning: too many arguments for format [-Wformat-extra-args]
     scanf("%lld", &test);
           ^~~~~~
test.c:7:14: warning: unknown conversion type character ‘l’ in format [-Wformat=]
     scanf("%lld", &test);
              ^
test.c:7:11: warning: too many arguments for format [-Wformat-extra-args]
     scanf("%lld", &test);
           ^~~~~~

Removing -Wall removes both warnings, without -pedantic I can compile without warnings line 6 (%I64d) but not line 7 (%lld).

1
Please stop tagging unrelated languages, your question is about C. You're using a C compiler to compile a program written in C language. - Antti Haapala
I have no experience with this, but you might want search for -D__USE_MINGW_ANSI_STDIO for a workaround. It might help you (?). - user694733
@Someprogrammerdude Windows MingW GCC will know it will target a b0rken libc - Antti Haapala

1 Answers

-1
votes

If you want to compile to Microsoft platform, you cannot be pedantic about following the standard. Embrace, extend (and extinguish)! Remove the -pedantic or get a proper C99/C11/C17 implementation.


C89 does not support %lld. It seems you need to disable -Wformat if you happen to target a library that supports it as an extension.