comma operator

John Hascall hascall at atanasoff.cs.iastate.edu
Sat Aug 5 04:28:48 AEST 1989


In article <9736> debra at alice.UUCP () writes:
}In article <13074> robert at arizona.edu (Robert J. Drabek) writes:
  
     [... comma stuff ...]

}The following is also a problem:
}if i have something like
}	if (e)
}		return;
}and want to get some debug output, i would try
}	if (e)
}		printf("Hi\n"),return;
}but this gives syntax error. (at least in the compilers i've tried)
}Note that
}	if (e)
}		printf("Hi\n"),exit();
}compiles fine. It's just that "return" is treated differently.


     Return is "treated differently" because it is a statement,
     not an expression--exit being a function is an expression.

     (wouldn't it be even more obfuscating and fun is all C
     statements were also expressions!! [holy shades of BLISS])


     I use something like this for that reason:

     #define GAG(msg,cond)   return(printf("...%s\n", msg), cond)

     if (e) GAG("Why the devil is `e' true?", ERR_ETRUE);


John Hascall
ISU Comp Center
Ames IA



More information about the Comp.lang.c mailing list