error: unknown conversion type character 'l' in format - scanning long long

☆樱花仙子☆ 提交于 2020-02-01 10:06:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!