Re: First C program

Barbara Morris <[email protected]>
Newsgroups gmane.comp.lang.as400.c
Message-ID <[email protected]>
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.

-- 
Barbara

-- 
This is the Bare Metal Programming IBM i (AS/400 and iSeries) (C400-L) mailing list
To post a message email: C400-L-Zwy7GipZuJhWk0Htik3J/[email protected]
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request-Zwy7GipZuJhWk0Htik3J/[email protected]
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.