First C Program

Frank Kolmann <[email protected]>
Newsgroups gmane.comp.lang.as400.c
Message-ID <CAB-SQvj6iwARzcBS2ASAo4asWzhN4V8_gOWh7NLJajD-_yjhbA@mail.gmail.com>
Hi Barbara



Thank you for your kind information, much appreciated.

I am afraid I have been tempted by the dark side.

I admit I got the code from an IBM book.

ILE C for AS/400(R) Programmer's Guide Version 4   pp160



I am still learning how to apply Paul Contes guidelines.

Hopefully I will keep to the light.



Frank





>*Subject: Re: First C program

> *From: Barbara Morris <bmorris@xxxxxxxxxx>

> *Date: Wed, 02 Apr 2014 15:52:03 -0400

>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.
-- 
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.