Skip to contentSkip to conversation

How to write elegant C coding

DISCUSSION krishna 5 participants 6 messages Jan 5, 2005

lore
Share & tools
lore

krishna

author
#0 lore raw

Hi All,

Can any one tell me sources to refer to write elegant C coding/ best
practices in C coding.

Regards,
Krishna Chaitanya

#1 lore raw
Quoted 3 lines · krishna

Hi All,
Can any one tell me sources to refer to write elegant C coding/
best practices in C coding.

Check the kernel sources under Documentation/CodingStyle

Cheers,
Con

author
#2 lore raw

What I mean is both elegant and _efficient_ best practices in C coding.

Quoted 13 lines · Con Kolivas
Quoted 3 lines · krishna

Hi All,
Can any one tell me sources to refer to write elegant C coding/
best practices in C coding.

Check the kernel sources under Documentation/CodingStyle

Cheers,
Con

#3 lore raw
Quoted 2 lines · krishna

What I mean is both elegant and _efficient_ best practices in C coding.

practice.

Quoted 20 lines
Quoted 7 lines · Con Kolivas
Quoted 3 lines · krishna

Hi All,
Can any one tell me sources to refer to write elegant C coding/
best practices in C coding.

Quoted 6 lines

Check the kernel sources under Documentation/CodingStyle

Cheers,
Con

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 4 lines
Tim Hockin
[email protected]
Soon anyone who's not on the World Wide Web will qualify for a government 
subsidy for the home-pageless.
#4 lore raw
In reply to krishna
Quoted 1 line · krishna

What I mean is both elegant and _efficient_ best practices in C coding.

Documentation/CodingStyle is well worth a read. Also for that matter just reading a lot of good code helps you write good code as reading helps you learn a language better.

Efficiency is a harder subject: Remember that efficient code still must be easy to understand so often is about algorithms not language, and in part about hardware.

On the hardware side - the book "Unix systems for modern architectures"

But as Tim righly said "practice"

Alan

#5 lore raw
In reply to krishna

krishna <[email protected]> said:

[...]

Quoted 1 line

What I mean is both elegant and _efficient_ best practices in C coding.

Look for "Writing Efficient Programs", by Jon Bentley (sadly out of print), and his "Programming Pearls" (2nd edition).

Keep in mind that "efficient" is mostly a thing of overall organization and careful design (and data structure definition), not detailed programming. Microoptimizations are usually counter-productive, at least by making the code unnecessarily hard to read; current compilers aim at generating code from "normally written C" that is at least as good as that a competent assembly programmer would write with care (and often writing "more efficient source code" just confuses the compiler into giving worse results). Better aim at understandable, easy to get right code. If you _measure_ later that it is too slow/large/..., _then_ go back and see how to make it better. So Documentation/CodingStyle is an excellent starting point.

Signature · 4 lines
Dr. Horst H. von Brand                   User #22616 counter.li.org
Departamento de Informatica                     Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria              +56 32 654239
Casilla 110-V, Valparaiso, Chile                Fax:  +56 32 797513