3 ms·
For the sake of job security, I propose using the comma operator to put the entire loop body within the for() parentheses, and replace the block with a semicolo
by nitrogen 13y ago
For the sake of job security, I propose using the comma operator to put the entire loop body within the for() parentheses, and replace the block with a semicolon:
// Pure C99 (prints an invalid character at the end)
for(
FILE *f = fopen("/etc/fstab", "r");
!feof(f) || (fclose(f), 0);
putchar(fgetc(f))
) ;
// C99+POSIX
for(
int fd = open("/etc/fstab", O_RDONLY), c = 0;
read(fd, &c, 1) || (close(fd), 0);
write(1, &c, 1)
) ;