Use of expression values in C

Peter Ludemann ludemann at ubc-cs.UUCP
Sun Jul 14 04:57:44 AEST 1985


For those who think "if ((foo=fopen(filename,"r"))==NULL) { ... }"
is hard to understand, why not create a macro to handle this:
#define opentest(filename,mode,ptr) ((ptr=fopen(filename,mode)==NULL)
and then you can write "if (opentest(filename, "r", foo)) { ... }"
To understand this, you just have to refer to the usual 10 pages of inscrutable
#defines which come with the program -).
But I do think that the macro approach is slightly more readable.
It almost looks like a subroutine call with a "var" parameter.



More information about the Comp.lang.c mailing list