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)
int main(void) { printf("Press a key. ENTER would be nice :-)\n\n"); printf("The expression getchar() != EOF evaluates to %d\n", getchar() != EOF); return 0; }