On Thu, 16 Feb 2006, Olwe Bottorff wrote:
> I'm reading "Code Reading," a very interesting book.
> He's talking about file pointers and there's a BSD OS
> line (ftpd.c) that goes like this:
>
> fin = fopen(name,"r"), closefunc = fclose;
Worse yet, it's comma operator abuse. Of course, pretty much all use of
the comma operator is abuse of the comma operator.
>
> I've never seen two things being done on the same
> line. It's just
>
> fin = fopen(name,"r");
> closefunc = fclose;
This code executes exactly the same as the code above. Unless they're
doing something really wonky, like:
x = (fin = fopen(name, "r"), closefunc = fclose);
In which case the code should be rewritten as:
fin = fopen(name, "r");
closefunc = fclose;
x = closefunc;
and the author hunted down and shot.
> right? Or am I missing something?
C doesn't care about whitespace generally. There is no difference, to C,
between:
fin = fopen(name, "r"); closefunc = fclose;
and splitting it into two lines. Heck, you could even do:
fin
=
fopen
(
name
,
"r"
)
;
closefunc
=
fclose
;
and C would care. It's still bad style.
Brian