源码:
#include <stdio.h>
int main(int argc, char const *argv[])
{
int c;
while( c = getchar() != EOF )printf("%d \n", c);
printf("%d - at EOF \n",c );
return 0;
}
系统环境:Mac OS X 10.8.4
Clang编译报错:
$clang -v
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.4.0
Thread model: posix
$clang 1-6.c
1-6.c:34:11: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
while( c = getchar() != EOF )
~~^~~~~~~~~~~~~~~~~~
1-6.c:34:11: note: place parentheses around the assignment to silence this warning
while( c = getchar() != EOF )
^
( )
1-6.c:34:11: note: use '==' to turn this assignment into an equality comparison
while( c = getchar() != EOF )
^
==
1 warning generated.
Gcc编译可以通过:
$gcc -v
Using built-in specs.
Target: i686-apple-darwin11
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
但是结果很诡异,多出一个1来,
$./a.out
qaz
1
1
1
1
clang编译不通过好理解,gcc下面为什么多出个1呢.
#include <stdio.h>
int main(int argc, char const *argv[])
{
int c;
while( c = getchar() != EOF )printf("%d \n", c);
printf("%d - at EOF \n",c );
return 0;
}
系统环境:Mac OS X 10.8.4
Clang编译报错:
$clang -v
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.4.0
Thread model: posix
$clang 1-6.c
1-6.c:34:11: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
while( c = getchar() != EOF )
~~^~~~~~~~~~~~~~~~~~
1-6.c:34:11: note: place parentheses around the assignment to silence this warning
while( c = getchar() != EOF )
^
( )
1-6.c:34:11: note: use '==' to turn this assignment into an equality comparison
while( c = getchar() != EOF )
^
==
1 warning generated.
Gcc编译可以通过:
$gcc -v
Using built-in specs.
Target: i686-apple-darwin11
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
但是结果很诡异,多出一个1来,
$./a.out
qaz
1
1
1
1
clang编译不通过好理解,gcc下面为什么多出个1呢.