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?
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:
I think
#ifdef _WIN32
is better — it should work at other contest systems also.Or use
"%I64lld"
everywhere without any conditions. Yes, it works.in MinGW for g++ 4.4.1
"%I64lld"
got warningunknown conversion type character 'l' in format
Warning, but 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.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.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
You should know that the functions like
scanf
andprintf
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)Just say, fuck windows.
^ So much this