Блог пользователя nivin

Автор nivin, 11 лет назад, По-английски

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?

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
11 лет назад, # |
Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится

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 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

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

    • »
      »
      »
      11 лет назад, # ^ |
        Проголосовать: нравится +5 Проголосовать: не нравится
      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 лет назад, # ^ |
        Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

        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 лет назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          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 лет назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

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 лет назад, # |
  Проголосовать: нравится -8 Проголосовать: не нравится

Just say, fuck windows.