[net.misc] C coding style

mp (06/27/82)

A project I'm working on is an attempt to build a language-based editor.
I've come to the conclusion that forcing indentation rules
on people is counterproductive, so I'd like to instead offer
the user his choice of indentation rules (that is, the editor
keeps a copy of the program in some internal form, and displays
it differently for each user who edits the program source file).

This message is a request for a survey; I'd like to find out
the various rules people use to indent C programs, and I also
want to hear about your C coding style in general.

So far, I've seen two proposed standards (Alan Glasser's 1979
BTL memo, and the Stanford Network Graphics project style sheet), and
they differ a good deal.  If people would like to see Stanford's
(it's about 4 pages long), I can send it out.

The rest of this message is rather nitpickety, so if you're
not interested in the topic, hit DEL now.

First, what rules do you have for capitalizing #defined constants
and global variables?

Are parameter declarations on (1) the same line as the procedure,
(2) on the following line, but not indented, or (3) on the following
line, indented?

How do you place the curly braces that delimit procedure, if, while,
do, and switch bodies?

Do you indent by 2, 4, or 8 spaces?

How do you write comments?
/*************************************
 * Do block comments look like this? *
 *************************************/

/*
 * 	Or like this?
 */

/* do your 1-line comments always extend to col 79?			     */


Program structure: In what order do you place
- initial descriptive comments
- #included files
- external and global declarations
- constant and macro #definitions
- type definitions
- procedure and function definitions

Finally, when do you put a space in front of a left paren?  This
may sound like a dumb question, but I know someone who is very
consistent:
	if (condition)	-- space after an "if"
	a = foo(b,c,d)  -- no space in a proc. call
	foo (how, arg1, arg2)  -- space after proc name when it's
			       -- the proc's definition

Right now, I'd just like to get some sampling of people's preferences.
Please mail replies to me, unless you have some wonderfully
lucid ideas about programming style that you can share with the
entire newsgroup.  I'm reachable as {mhtsa!}eagle!mit-vax!mp,
Shasta!mp, or {ucbvax!}MP@ML.

	Mark