× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On 2014-04-02 02:32, frank kolmann wrote:
...
1. Don't use = in an if statement expression, unless it is
absolutely necessary.

Frank, this code seems to violate that guideline.

if ((pf = _Ropen(PFILENAME, "rr")) EQ NULL)
{ printf("can't open file %s\n", PFILENAME); exit(1); }

I think it's a very good guideline. I would code that like this. (I'll go along with the EQ ...)

pf = _Ropen(PFILENAME, "rr");
if (pf EQ NULL)
...

I would also spread out the code under the "if". I think it's too easy to miss the exit statement when the printf and exit are on the same line.
I also think it's easier to see exactly what code is conditioned by the "if" when the curly braces are coded on their own lines.

pf = _Ropen(PFILENAME, "rr");
if (pf EQ NULL)
{
printf("can't open file %s\n", PFILENAME);
exit(1);
}

This code takes up a few more lines than yours, but I find it much more readable-at-a-glance. If you want to collapse the code to make it easier to follow the whole program, you could put all the opens into a separate function.


As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.