Question 17.1

What's the best style for code layout in C?

K&R, while providing the example most often copied, also supply a good excuse 
for disregarding it:
The position of braces is less important, although people hold passionate 
beliefs. We have chosen one of several popular styles. Pick a style that 
suits you, then use it consistently.

It is more important that the layout chosen be consistent (with itself, and 
with nearby or common code) than that it be ``perfect.'' If your coding 
environment (i.e. local custom or company policy) does not suggest a style, 
and you don't feel like inventing your own, just copy K&R. (The tradeoffs 
between various indenting and brace placement options can be exhaustively and 
minutely examined, but don't warrant repetition here. See also the Indian 
Hill Style Guide.)

The elusive quality of ``good style'' involves much more than mere code 
layout details; don't spend time on formatting to the exclusion of more 
substantive code quality issues.

See also question 10.6.

References: K&R1 Sec. 1.2 p. 10
K&R2 Sec. 1.2 p. 10

comp.lang.c
;)

to those of you who complained about my style - at least it's consistent. :) 
:) Ummmm....

Anyone ever look at an isset like this:
#define ISSET (*((a)+((b)>>5))&(1<<((b)&0x1f)))

Since we're dividing by a power of two: b>>5 (32)
and to get the bit you're looking for... b&0x1f :) :)

Hmmmm... how's that for efficiency?

Mark


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


Reply via email to