編輯刪除的第一個警告%llx格式說明符:無效警告?
下面的代碼將按預期在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
,雖然(我)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.
所以這是一個錯誤,肯定?
它的標籤爲C++。你可以得到的最好是'std :: cout << std :: hex << x <<'\ n';' – MSalters 2011-04-05 07:46:33
是的,對於long long類型沒有標準的說明符。但'lld'和'llx'是最便攜的。 – 2011-04-05 07:49:13
@ MSalters:現在我已經添加了'C++ 0x'標記,以使'long long'成爲標準類型(這就是爲什麼我將它標記爲「C++」,但現在我意識到「long long」不是標準的在'C++ 0x'之前的'C++'中)。 – TonyK 2011-04-05 08:15:28