このファイルのコンパイル時にGCCは私にの同一の警告を示し、なぜ私は好奇心が強い:GCCは、不正なprintfフォーマット指定子に対して重複した警告を表示するのはなぜですか?
$ clang test.c
test.c:6:14: warning: conversion specifies type 'int' but the argument has type 'long' [-Wformat]
printf("%i\n", foo);
~^ ~~~
%ld
test.c:6:14: warning: conversion specifies type 'int' but the argument has type 'long' [-Wformat]
printf("%i\n", foo);
~^ ~~~
%ld
2 warnings generated.
任意のアイデア:
$ cat test.c
#include <stdio.h>
int main (int argc, char const *argv[])
{
long foo = 0l;
printf("%i\n", foo);
return 0;
}
$ gcc-4.2 -Wall test.c
test.c: In function ‘main’:
test.c:6: warning: format ‘%i’ expects type ‘int’, but argument 2 has type ‘long int’
test.c:6: warning: format ‘%i’ expects type ‘int’, but argument 2 has type ‘long int’
は興味深いことに、クランは、2回の警告を与えますか?詳細については
:
$ gcc-4.2 -v
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/gcc/gcc-5666.3~278/src/configure
--disable-checking --enable-werror --prefix=/usr --mandir=/share/man
--enable-languages=c,objc,c++,obj-c++
--program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib
--build=i686-apple-darwin11 --program-prefix=i686-apple-darwin11-
--host=x86_64-apple-darwin11 --target=i686-apple-darwin11
--with-gxx-include-dir=/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)
$ clang -v
Apple clang version 2.1 (tags/Apple/clang-163.7.1) (based on LLVM 3.0svn)
Target: x86_64-apple-darwin11.1.0
Thread model: posix
EDIT: 'マルチアーキテクチャ' 仮説の数は、良い響きを示唆しているが、私はそれが正しいだか分かりません。私が-arch
で単一のアーキテクチャを強制すると、2つの警告が出ます。 -arch x86_64 -arch i386
と指定すると、重複した警告が2セットあります。
$ gcc-4.2 -Wall -arch x86_64 test.c
test.c: In function ‘main’:
test.c:6: warning: format ‘%i’ expects type ‘int’, but argument 2 has type ‘long int’
test.c:6: warning: format ‘%i’ expects type ‘int’, but argument 2 has type ‘long int’
$ gcc-4.2 -Wall -arch x86_64 -arch i386 test.c
test.c: In function ‘main’:
test.c:6: warning: format ‘%i’ expects type ‘int’, but argument 2 has type ‘long int’
test.c:6: warning: format ‘%i’ expects type ‘int’, but argument 2 has type ‘long int’
test.c: In function ‘main’:
test.c:6: warning: format ‘%i’ expects type ‘int’, but argument 2 has type ‘long int’
test.c:6: warning: format ‘%i’ expects type ‘int’, but argument 2 has type ‘long int’
編集:私は、すべての警告のタイプのdupesを得ることはありません。 -Wformat
は私がこれまで出会った唯一のものです。たとえば、私が未使用の変数を投げた場合、そのことについて警告が1つだけ得られます。
$ cat test.c
#include <stdio.h>
int main (int argc, char const *argv[])
{
long foo = 0l;
long bar;
printf("%i\n", foo);
return 0;
}
$ gcc-4.2 -Wall test.c
test.c: In function ‘main’:
test.c:7: warning: format ‘%i’ expects type ‘int’, but argument 2 has type ‘long int’
test.c:7: warning: format ‘%i’ expects type ‘int’, but argument 2 has type ‘long int’
test.c:6: warning: unused variable ‘bar’
FWIW、私は唯一のエラーメッセージが表示されます。これはあなたのビルドシステムの成果物ではないと確信しています。これは何とかGCCを2度呼びますか? –
ありがとうございました。私は全くわからない、それはおそらくそうである。: -/ –
重複する警告が表示されません。しかし、それはあなたがとにかく修正する必要があるという警告です... –