编辑了以删除第一个警告
在g++ 4.4.0中,以下代码在mingw32下正常工作:
#include <cstdio>
int main()
{
long long x = 0xdeadbeefc0defaceLL ;
printf ("%llx\n", x) ;
}
但是,如果我使用-Wall
启用所有警告,它会说:
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
%lld
也是如此。这在新版本中是固定的吗?
再次编辑以添加:
如果我指定-std=c++0x
,警告就不会消失,尽管(i) long long
是一个标准类型,(ii) %lld
和%llx
似乎得到了官方的支持。例如,从21.5数字转换第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.
所以这是个窃听器,对吧?
发布于 2011-04-05 07:40:43
long long x = 0xdeadbeefc0defaceLL; // note LL in the end
并且没有ll
长度说明符用于printf
。你能得到的最好结果是:
printf ("%lx\n", x); // l is for long int
我已经在我的g++上测试了您的示例,它编译时没有错误,甚至没有-std=c++0x
标志:
~$ g++ -Wall test.cpp
~$ g++ --version
g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3
所以,是的,这个在新版本中是固定的。
发布于 2011-04-05 07:41:53
对于第一次警告,我可以说您必须使用0xdeadbeefc0defaceLL
而不是0xdeadbeefc0deface
。在此之后,其他警告可能也会过去。
发布于 2011-08-05 02:52:25
我收到了使用windows/mingw32 32编译C的相同警告。
warning: unknown conversion type character 'l' in format
所以是的,可能是编译器/平台特有的错误。
https://stackoverflow.com/questions/5548670
复制相似问题