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

12,227

Solution 1

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.

Solution 2

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.

Share:
12,227

Related videos on Youtube

Tomáš Zato
Author by

Tomáš Zato

It might be easier to hire new management than to get a new community of volunteers. - James jenkins If you play League of Legends, check my repository: http://darker.github.io/auto-client/ I no longer play and I am actively looking for someone to maintain the project. It helped thousands of people, literally.

Updated on June 03, 2022

Comments

  • Tomáš Zato
    Tomáš Zato about 2 years

    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

    • hobbs
      hobbs about 10 years
      Try using something like -std=gnu99 instead of c99.
    • WhozCraig
      WhozCraig about 10 years
      If rule is int64_t instead, try scanf("%" SCNd64, &rule); Be sure to include inttypes.h and stdint.h. See this for more info. It should be supported in C99.
    • James King
      James King about 10 years
      I deleted an answer I had posted; what you are doing complies and executes fine for me with the same gcc options on Linux, so I'm thinking it's something to do with MingW.
    • M.M
      M.M about 10 years
      Your implementation is not C99-compliant. Are you sure that -std=c99 is being passed when the first error message is generated?
    • Tomáš Zato
      Tomáš Zato about 10 years
      It would be not the first time when the compilation passed very differently on windows and linux.
    • Tomáš Zato
      Tomáš Zato about 10 years
      -std=gnu99 yields the same errors.
    • Joseph Quinsey
      Joseph Quinsey over 7 years
  • Pascal Cuoq
    Pascal Cuoq about 10 years
    It doesn't: MinGW re-uses as many software components from Windows as possible, and this includes the C runtime. MinGW's GCC is a chimera of a C99 compiler with a non-C99 standard library.
  • Tomáš Zato
    Tomáš Zato about 10 years
    Unfortunatelly, after including inttypes.h, I'm getting the same errors as before. How can it be possible for a compiler being unable to do such a trivial thing? The command line switches must be kept - the same switches are being used on evaluation server (I'm doing a programming homework).
  • Jens Gustedt
    Jens Gustedt about 10 years
    As Pascal says, your platform includes components from Windows that aren't C99 compliant. On the evaluation server, if this isn't on a Windows system, you might have more luck.
  • Rajesh
    Rajesh over 6 years
    Even though we get warning for lld, I observed that correct value is printed (MinGW. In below case, the result printed is 6442450950 unsigned long long var6=2147483650*3; printf("var6 =%lld\n",var6);
  • PypeBros
    PypeBros about 6 years
    @rajesh, that's because the libc, not the compiler, does the printing. The libc does the job as the implementation says. The compiler additionally check whether a <standard>-compliant library would correctly handle formatting strings.
  • Rajesh
    Rajesh about 6 years
    I think these issues/features make C language more bug prone.