|
|
|
|
|
by inferiorhuman
1010 days ago
|
|
It might be ugly, but that is idiomatic C code. C didn't even have boolean types until C99, and even then it's an "extension" of an integer type. You could argue about the loop itself, after all K&R specified "for(;;)", but the other commonly used (ergo idiomatic) infinite loops use precisely the same number of lines.
"while(1)" is a perfectly idiomatic manner to create an infinite loop. Likewise a void return type for main was entirely legal until C99. The BSD yes(1) I've laying around only prints the first argument, so flag parsing? What flag parsing? Yes in nine lines of C inclusive of preprocessor macro invocations and white space. #include <stdio.h>
int main(int argc, char **argv) {
const char *phrase = argc > 1 ? argv[1] : "y";
while (1) {
printf("%s\n", phrase);
}
return 0;
}
|
|