This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: A question on coding conventions
Hi,
On Sat, 26 Mar 2011, Levon Haykazyan wrote:
> I was trying to configure vim to work better with gcc coding
> conventions. When I set 'tab' symbol to be interpreted as 2 spaces, I
> noticed that a lot of formatting in e.g. gcc/cp/parser.c was gone.
Yeah, never change tabstop, change shiftwidth instead. I'm using these
for vim:
set shiftwidth=4
set tabstop=8
set cindent
set cinoptions={.5s,g0,p5,t0,(0,^-0.5s,n-0.5s
(similar results can be achieved with sw=2 and adjustments to the
options, but for some reason I like to think of the GNU conventions to
be based on a base indentation of 4 positions with some extra rules
where only half indentations are used)
> A bit of research showed that in a lot of places 'tab' was used for 8
> spaces. I've looked in gcc and gnu coding conventions but didn't find
> anything about this. So my question is whether such usage of 'tab'
> symbol is recommended by coding conventions or 8 spaces should be used
> instead.
Given an indentation of N positions we use N/8 tabs and N%8 spaces, yes.
(some authors use only spaces, so that's not a hard rule, but never
write your code with tabstops set to anything else than 8).
Ciao,
Michael.