R
Roy Smith
The following code appears to be illegal:
while ((int c = getchar()) != EOF) {
putchar (c);
}
I tried it on two different compilers (Sun workshop and gcc), and both
give some variation on syntax error at "int c =". The very similar:
for (int c = getchar(); c != EOF; c = getchar()) {
putchar (c);
}
compiles fine. What's going on here?
while ((int c = getchar()) != EOF) {
putchar (c);
}
I tried it on two different compilers (Sun workshop and gcc), and both
give some variation on syntax error at "int c =". The very similar:
for (int c = getchar(); c != EOF; c = getchar()) {
putchar (c);
}
compiles fine. What's going on here?