home | list info | list archive | date index | thread index

Re: [OCLUG-Tech] White spaces in 'C' /kernel programming??

  • Subject: Re: [OCLUG-Tech] White spaces in 'C' /kernel programming??
  • From: Richard Guy Briggs <rgb [ at ] tricolour [ dot ] net>
  • Date: Wed, 2 Sep 2009 13:14:55 -0400
On Wed, Sep 02, 2009 at 11:44:18AM -0400, William Case wrote:
> Hi;

Hi Bill,

> I have just been reading Documentation/Coding Style for the 2.6 kernel.
> It goes on at length about when and when not to use white spaces.  
> 
> E.g.
> "Do not leave trailing white space at the ends of lines.  Some editors
> with "smart" indentation will insert white space at the beginning of new
> lines as appropriate, so you can start typing the next line of code
> right away.  ..... "
> 
> In other places, people go to great lengths and use specialized programs
> to remove white spaces, especially trailing white spaces.  Yet, I have
> read, in K&R and elsewhere, that 'C' compilers like gcc just ignore or
> throw out any unneeded white space.
> 
> So, why the concern over extra white spaces in 'C' code?

The compiler won't care.  It is the source code management tools that
will have a bit more difficulty.  In particular, trailing whitespace
might not look any different to you on your screen, but it does look
different to diff(1), unless you use the "-B" and/or "-b" switches.

It can be a challenge to merge code if you have inadvertantly added
whitespace to existing, or to your own source code.  I haven't looked at
the standards in a while, but it probably also has something to say
about leading whitespace being consistently spaces or tabs, but not
both, and a standard conversion for tabs to spaces.

Whitespace *is* very important in Python, but you haven't asked about
that...

> Regards Bill

	slainte mhath, RGB

--
Richard Guy Briggs               --  ~\    -- ~\            <hpv.tricolour.net>
<www.TriColour.net>                --  \___   o \@       @       Ride yer bike!
Ottawa, ON, CANADA                  --  Lo_>__M__\\/\%__\\/\%
Vote! -- <greenparty.ca>_____GTVS6#790__(*)__(*)________(*)(*)_________________