% llx format: invalid warning?

Edited to remove the first warning

The following code works as expected in g ++ 4.4.0 under the name mingw32:

#include <cstdio> int main() { long long x = 0xdeadbeefc0defaceLL ; printf ("%llx\n", x) ; } 

But if I turn on all warnings using -Wall , it says:

 f.cpp: In function 'int main()': f.cpp:5: warning: unknown conversion type character 'l' in format f.cpp:5: warning: too many arguments for format 

Same with the %lld . Is this fixed in newer versions?

Edited again to add:
The warning does not disappear if I specify -std=c++0x , although (i) long long is the standard type, and (ii) %lld and %llx seem to be officially supported. For example, from 21.5 Numeric Conversions , clause 7:

Each function returns a string object holding the character representation of the value of its argument that would be generated by calling sprintf(buf, fmt, val) with a format specifier of "%d", "%u", "%ld", "%lu", "%lld", "%llu", "%f", "%f", or "%Lf", respectively, where buf designates an internal character buffer of sufficient size.

So this is a mistake?

+4
source share
4 answers
 long long x = 0xdeadbeefc0defaceLL; // note LL in the end 

And there will be no length specifier for printf . The best you can get is:

 printf ("%lx\n", x); // l is for long int 

I tested your sample on my g ++, it compiles without errors even without -std=c++0x :

 ~$ g++ -Wall test.cpp ~$ g++ --version g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3 

So yes, this is fixed in newer versions.

+3
source

For the first warning, I can say that you should use 0xdeadbeefc0defaceLL instead of 0xdeadbeefc0deface . Other warnings may go after this.

+1
source

I get the same warning compiling C using windows / mingw32.

 warning: unknown conversion type character 'l' in format 

So yes, probably a bug with the compiler / platform.

+1
source

This is a Mingw related issue because it invokes the Windows native runtime for certain things, including this. See this answer .

%I64d works for me. The answer above has a more portable, albeit less readable solution.

+1
source

Source: https://habr.com/ru/post/1346683/


All Articles