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



Hi, Barbara, and Frank:

This reply is mostly "for the archives". ...

I think a much improved style for C code can be illustrated by slightly re-formatting your last code example, as shown below:

static _RFILE *fOpenFile( const char *filename,
const char *openmode,
int rc ) {
_RFILE *f;
f = _Ropen(filename, openmode);
if (f EQ NULL) {
printf("can't open file %s\n", PFILENAME);
exit(rc);
}
return f;
}

Basically, my recommendations boil down to:

1. indent just two or three spaces for each level of nesting (I prefer 3)

2. use the "{" and "}" even if only one statement or function is coded;

3. put "{" on the same line as the function header or structure declaration or "if " or "while " or "for" statement ...

4. place the corresponding "}" on a line by itself, indented to "line up" with the code above it

Here is an example of an if statement with an "else" clause:

if (x == y) {
printf("do something...\n");
}
else {
printf("do something else ...\n");
}

Here is another alternative:

if (x == y) {
printf("do something...\n");
} else {
printf("do something else ...\n");
}

Whatever you decide to do, strive for consistency.

All the best,

Mark S. Waterbury

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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.