问题
I'm trying to get long long
from the console using standard IO function scanf
. I started with %lld
:
scanf("%lld", &rule);
That throws:
error: unknown conversion type character 'l' in format [-Werror=format=]
I've found more workarounds, but they too throw errors:
scanf("%I64d", &rule);
->error: ISO C does not support the 'I64' ms_scanf length modifier [-Werror=format=]
scanf("%"SCNd64"", &rule);
->error: expected ')' before 'SCNd64'
Am I doing something wrong? Is there an another trick?
I'm compiling on very recent version of MinGw GCC with these flags: -pedantic -Wall -Werror -std=c99 -g -D HOME=1
回答1:
for SCNd64
and similar, you'd have to use
#include <inttypes.h>
but all of this is only supposed to work if your compiler supports C99. Your first error message is a strong indication that it doesn't, or that you didn't give the right commandline switches.
回答2:
Just wanted to add this snippet too:
MinGW-w64 - for 32 and 64 bit Windows / [Mingw-w64-public] -Wformat and %llu
the issue is that formatter-width specifier %ll isn't supported for all msvcrt-DLL versions, therefore gcc warns about its use. The variant for specifying 64-bit integer-scalar-width in formatter for msvcrt in a backward-compatible way is by using %I64.
Use %I64u on Windows, or just use inttypes.h PRIuMAX.
If you must use %llu, define __USE_MINGW_ANSI_STDIO macro before including stdio.h. Be aware that if you do this, MS type %I64* format will no longer work.
来源:https://stackoverflow.com/questions/23718110/error-unknown-conversion-type-character-l-in-format-scanning-long-long