cr88192 said:
<snip>
>
> now, I usually code in notepad,
Oh dear. :-)
> which has inflexible 8-space tabs, so
> usually I use this.
> if the tab space is adjustable, usually I like 4 space tabs.
Tab/space wars are so 1990s, though, aren't they?
> 2 or 3 spaces is IMO too little.
And IMO 3 is too many. Vive la difference!
> 1 space is just horrid (may as well not indent at all...).
Agreed.
> usually, I put opening and closing braces on their own lines, and
closing
> braces are indended the same as the opening braces.
Agreed again.
You forgot <stdio.h>
> int main(int argc, char *argv[])
> {
> FILE *fd;
> if(argv<2)
You meant argc.
> {
> printf("usage: %s <filename>\n", argv[0]);
If argc is 0, the behaviour is undefined. If it is >= 1, argv[0] must
represent the program name in some way, but need not be a string
representing the invocation name for the program. It could even be a pid!
> return(-1);
This has no ****table meaning (and the parentheses are redundantly
superfluous).
> }
>
> fd=fopen(argv[1], "rb");
> ...
> return(0);
Again, the parentheses are superfluously redundant.
> }
>
> note that EXIT_SUCCESS and EXIT_FAILURE are considered "more correct"
for
> main return values,
0 is fine - it means success.
> but 0 and -1 are more common/traditional.
A -1 return value has no de jure meaning in C (which is, at least, in
keeping with the better kinds of tradition - if we knew why we did them,
they wouldn't be traditions!).
To indicate failure ****tably, use EXIT_FAILURE.
> IMO, both forms:
> if(...)
> {
>
> and:
> if(...) {
>
> are fairly common and acceptable, but most people put the brace on its
> own line for functions, and rarely for structs or unions.
The word "most" is arguable. K&R's style is perniciously persistent even
now. And a significant number of Allman adherents /do/ put a struct brace
on its own line.
> it is common for commas to be followed by a space ("f(x, y);" but not
> "f(x,y);").
True, and wise.
> some people precede/follow parens and/or operators with spaces.
True, and a matter of taste, I think. My own taste is for parentheses not
to "command" any whitespace, but for binary operators to be separated from
their operands by a space.
> if certain single-letter variable names are used (especially,
> i,j,k,s,t,...) it is almost obligatory that they be certain types (i,j,k
> are int, s,t are 'char *', ...).
No, not really. Common, yes. Obligatory? Hardly.
>
> return is often/usually written as if it were a function call (common in
> C, rare in C++).
return /isn't/ a function call, and it seems to me from perusing this
group
and from what I've seen of good C code (in well-regarded literature, in
workplaces, and on the Web) that few if any experienced C programmers
treat it like one.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www.
+rjh@[EMAIL PROTECTED]
users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


|