assignments in if statements
Bob Lied
lied at ihlts.UUCP
Sat Jun 29 10:21:49 AEST 1985
Regarding the debate about nesting assignments in if statements, such as
if ( (fp = fopen("foo", "r")) != NULL )
I prefer to make the assignment separate for the simple reason that
it gives me a place to set a breakpoint and test an alternate value
before the program decides what path to take. It's not quite so
useful in 'if' statements, but before a switch it comes in very handy.
For example,
c = getchar();
switch ( c ) switch ( c = getchar() )
In the example on the left, I can examine c before the program goes on,
and I can change it if I need to test a strange case; on the right,
I have to depend on the input data.
Bob Lied ihnp4!ihlts!lied
More information about the Comp.lang.c
mailing list