2005-01-05 03:33:39

by krishna

[permalink] [raw]
Subject: How to write elegant C coding

Hi All,

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

Regards,
Krishna Chaitanya


2005-01-05 03:41:02

by Con Kolivas

[permalink] [raw]
Subject: Re: How to write elegant C coding

krishna wrote:
> 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

2005-01-05 03:50:53

by krishna

[permalink] [raw]
Subject: Re: How to write elegant C coding


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

Con Kolivas wrote:

> krishna wrote:
>
>> 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
>
>

2005-01-05 03:55:53

by Tim Hockin

[permalink] [raw]
Subject: Re: How to write elegant C coding

On Wed, Jan 05, 2005 at 09:13:04AM +0530, krishna wrote:
>
> What I mean is both elegant and _efficient_ best practices in C coding.

practice.

> Con Kolivas wrote:
>
> >krishna wrote:
> >
> >>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
> >
> >
> -
> 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/

--
Tim Hockin
[email protected]
Soon anyone who's not on the World Wide Web will qualify for a government
subsidy for the home-pageless.

2005-01-05 05:16:31

by Alan

[permalink] [raw]
Subject: Re: How to write elegant C coding

On Mer, 2005-01-05 at 03:43, krishna wrote:
> 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

2005-01-05 06:51:04

by krishna

[permalink] [raw]
Subject: Re: How to write elegant C coding

Thank you very much.

2005-01-05 07:49:12

by Coywolf Qi Hunt

[permalink] [raw]
Subject: Re: How to write elegant C coding

I'd say better to study compile theory and a kind of compiler source code.


On Wed, 05 Jan 2005 12:14:19 +0530, krishna
<[email protected]> wrote:
> Thank you very much.
> -
> 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/
>


--
Coywolf Qi Hunt
Homepage http://sosdg.org/~coywolf/

2005-01-05 08:14:21

by Al Viro

[permalink] [raw]
Subject: Re: How to write elegant C coding

On Wed, Jan 05, 2005 at 03:49:07PM +0800, Coywolf Qi Hunt wrote:
> I'd say better to study compile theory and a kind of compiler source code.

Yes, gcc source definitely makes a great cautionary tale about the need of
writing elegant code and dreadful results of not doing so.

2005-01-05 15:13:15

by Horst H. von Brand

[permalink] [raw]
Subject: Re: How to write elegant C coding

krishna <[email protected]> said:

[...]

> 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.
--
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

2005-01-05 15:33:13

by Adrian von Bidder

[permalink] [raw]
Subject: Re: How to write elegant C coding (certainly OT)

On Wednesday 05 January 2005 09.14, Al Viro wrote:
> On Wed, Jan 05, 2005 at 03:49:07PM +0800, Coywolf Qi Hunt wrote:
> > I'd say better to study compile theory and a kind of compiler source
> > code.
>
> Yes, gcc source definitely makes a great cautionary tale about the need
> of writing elegant code and dreadful results of not doing so.


LOL

I specifically recommend the ARM backend. It was copied from some other
RISC target, then a ARM thumb (16bit instruction width) backend was split
from that, and finally the thumb and 32bit backends were merged again,
apparently without removing much of the duplicated code.

Fun.

-- vbi

--
featured link: http://fortytwo.ch/gpg/subkeys


Attachments:
(No filename) (691.00 B)
(No filename) (388.00 B)
Download all attachments

2005-01-06 15:24:24

by krishna

[permalink] [raw]
Subject: Re: How to write elegant C coding

Hi,

Thank you very much for refering me for "programming pearls".

Regards,
Krishna Chaitanya