nivin's blog

By nivin, 11 years ago, In English

Codeforces normally suggest us to use %I64 for long long. But when I try it in my g++ complier with ubuntu(12.04) I get a warning stated "warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’". Can anyone suggest how do i remove warning and what is %I64?

  • Vote: I like it
  • +2
  • Vote: I do not like it

| Write comment?
»
11 years ago, # |
Rev. 4   Vote: I like it 0 Vote: I do not like it

normally you should use %lld.

%I64d is VS extension, that currently works in mingw(used on codeforces too), but doesn't work on my g++ on ubuntu.

Codeforces version of mingw didn't support %lld some times ago. But now long long and %lld are in standard(c++11) and it's supported in mingw. So, I don't think it's possible that its support will be stopped. I think you may use %lld on CF now safely.

Small russian discussion.

You may also use this kind of code:

#ifdef ONLINE_JUDGE
#define LL "%I64d"
#else
#define LL "%lld"
#endif
...
long long x;
scanf(LL, &x);
  • »
    »
    11 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I think #ifdef _WIN32 is better — it should work at other contest systems also.

    Or use "%I64lld" everywhere without any conditions. Yes, it works.

    • »
      »
      »
      11 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      in MinGW for g++ 4.4.1 "%I64lld" got warning unknown conversion type character 'l' in format

    • »
      »
      »
      11 years ago, # ^ |
        Vote: I like it +5 Vote: I do not like it
      Or use "%I64lld" everywhere without any conditions. Yes, it works.

      No, it doesn't. This conversion specification is invalid and introduces undefined behavior (C99 7.19.6.1.9). On my system, for example, this prints a 64 character wide field.

      The best way is to use the standard %lld locally and on Codeforces, as MinGW now supports it.

      • »
        »
        »
        »
        11 years ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        Can you please tell what OS, compiler and version do you have? I wrote that comment to find the system where it doesnt work.

        What about %lld, it can be useless (like #ifdef ONLINE_JUDGE) at another online judged with Windows and older mingw.

        • »
          »
          »
          »
          »
          11 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          I have Linux and GCC 4.8; of course they don't know about I64.

          If you are worried about compatibility with older MinGW/VC++, then, as you yourself and riadwaw noted, you have to use

          #ifdef _WIN32
          #  define LLD "%I64d"
          #else
          #  define LLD "%lld"
          #endif
»
11 years ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

You should know that the functions like scanf and printf are actually provided by C runtime libraries. Glibc, which is your case, only supports standard "%lld", while MSVCRT contains non-standard extensions like "%I32d" and "%I64u" in addition. However, MinGW uses MSVCRT60, an ancient version of MSVCRT built before "%lld" became standard. That's why we have to use "%I64d" for and only for MinGW. (Suppose nobody uses VC6 anymore)

»
11 years ago, # |
  Vote: I like it -8 Vote: I do not like it

Just say, fuck windows.