Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: indentation
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 22 of 45 Topic 26110 of 26972
Post > Topic >>

Re: indentation

by Richard Heathfield <rjh@[EMAIL PROTECTED] > May 8, 2008 at 07:34 AM

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
 




 45 Posts in Topic:
indentation
"Bill Cunningham&quo  2008-05-08 00:51:07 
Re: indentation
Joe Wright <joewwright  2008-05-07 21:33:52 
Re: indentation
"Bill Cunningham&quo  2008-05-08 01:49:00 
Re: indentation
Ian Collins <ian-news@  2008-05-08 14:25:16 
Re: indentation
"Bill Cunningham&quo  2008-05-08 02:47:38 
Re: indentation
Mark McIntyre <markmci  2008-05-08 08:59:10 
Re: indentation
"rio" <a@[EM  2008-05-08 12:42:53 
Re: indentation
"Bill Cunningham&quo  2008-05-08 20:41:15 
Re: indentation
Keith Thompson <kst-u@  2008-05-08 14:39:29 
Re: indentation
"rio" <a@[EM  2008-05-09 10:18:36 
Re: indentation
"cr88192" <c  2008-05-09 17:29:48 
Re: indentation
"rio" <a@[EM  2008-05-09 10:22:29 
Re: indentation
"rio" <a@[EM  2008-05-09 16:57:33 
Re: indentation
pereges <Broli00@[EMAI  2008-05-09 02:25:56 
Re: indentation
Keith Thompson <kst-u@  2008-05-07 18:44:49 
Re: indentation
santiago538 <santiago5  2008-05-07 22:27:13 
Re: indentation
Andrew Haley <andrew29  2008-05-08 10:52:58 
Re: indentation
CBFalconer <cbfalconer  2008-05-07 21:36:33 
Re: indentation
"Bill Cunningham&quo  2008-05-08 20:43:25 
Re: indentation
CBFalconer <cbfalconer  2008-05-08 19:08:01 
Re: indentation
"cr88192" <c  2008-05-08 17:12:08 
Re: indentation
Richard Heathfield <rj  2008-05-08 07:34:17 
Re: indentation
brix99luftballons <bri  2008-05-08 11:26:57 
Re: indentation
pete <pfiland@[EMAIL P  2008-05-08 05:34:45 
Re: indentation
Richard Heathfield <rj  2008-05-08 09:39:42 
Re: indentation
brix99luftballons <bri  2008-05-08 16:26:24 
Re: indentation
Richard Heathfield <rj  2008-05-08 14:36:30 
Re: indentation
David Thompson <dave.t  2008-05-19 03:59:51 
Re: indentation
"cr88192" <c  2008-05-08 20:33:26 
Re: indentation
Flash Gordon <spam@[EM  2008-05-08 14:15:33 
Re: indentation
Richard Heathfield <rj  2008-05-08 14:17:54 
Re: indentation
Bart <bc@[EMAIL PROTEC  2008-05-08 05:11:49 
Re: indentation
Nick Keighley <nick_ke  2008-05-08 01:05:28 
Re: indentation
pereges <Broli00@[EMAI  2008-05-08 01:56:23 
Re: indentation
pete <pfiland@[EMAIL P  2008-05-08 05:11:00 
Re: indentation
CBFalconer <cbfalconer  2008-05-08 17:37:54 
Re: indentation
Nick Keighley <nick_ke  2008-05-09 00:25:50 
Re: indentation
Eligiusz Narutowicz<el  2008-05-08 13:35:45 
Re: indentation
Eligiusz Narutowicz<el  2008-05-08 13:38:31 
Re: indentation
"cr88192" <c  2008-05-09 17:11:40 
Re: indentation
Eligiusz Narutowicz<el  2008-05-08 14:23:27 
Re: indentation
"cr88192" <c  2008-05-09 16:43:23 
Re: indentation
Ben Bacarisse <ben.use  2008-05-08 18:07:27 
Re: indentation
Richard Heathfield <rj  2008-05-08 19:52:11 
Re: indentation
Jean-Marc Bourguet <jm  2008-05-09 02:19:27 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 16:06:45 CDT 2008.