APL\360

Fred Cisin cisin at xenosoft.com
Fri Jan 29 17:59:40 CST 2021


On Fri, 29 Jan 2021, Chuck Guzis via cctalk wrote:

> In the past (and occasionally today, I use the following construct:
>
> FILE *myfile;
>
> if ( !(myfile = fopen( filename, "r"))
> {
>  fprintf( stderr, "Couldn\'t open %s - exiting\n", filename);
>  exit (1);
> }
>
> Yes, it only saves a line, but neatly describes what's being done.
>
> --Chuck

Yes.
That is another excellent example of where you DO want to do an assignment 
AND a comparison (to zero).  A better example than my strcpy one, although 
yours does not need to save that extra line, but a string copy can't 
afford to be slowed down even a little.

That is why it MUST be a WARNING, not an ERROR.
Of course, the error is when that wasn't what you intended to do.



More information about the cctalk mailing list