What is the preferred code style for uclibc?
Bernhard Reutner-Fischer
rep.dot.nop at gmail.com
Tue Dec 2 13:53:22 UTC 2008
On Mon, Dec 01, 2008 at 08:44:55PM +0100, Denys Vlasenko wrote:
>Hi Bernhard, folks,
>
>Can you indicate what coding style you prefer
>in uclibc?
>
>Curretly we have a mixture of all kinds,
>GNU style with its uniquely difficult placement
>of {}s:
>
> if (set == NULL || signo <= 0 || signo >= NSIG)
> {
> __set_errno (EINVAL);
> return -1;
> }
ISTR that gcc uses this style:
$ cat ~/.vim/gcc_style.vim
" put this plugin into ~/.vim/gcc_style.vim and source it into your ~/.vimrc via
" source ~/.vim/gcc_style.vim
if exists("g:loaded_gcc_style") || &cp
finish
endif
let g:loaded_gcc_style = 1
augroup gcc_style
autocmd BufReadPost,FileReadPost * call s:maybe_gcc_style()
augroup END
if exists("*s:maybe_gcc_style")
finish
endif
let s:cpo_save = &cpo
set cpo&vim
function! s:maybe_gcc_style()
let s:i = 1 + 0
while s:i <= line("$") && s:i <= 25
let s:line = getline(s:i)
if s:line =~ '^\s*This\sfile\sis\spart\sof\sGCC.*'
" gcc-mode
set cino=:s,{s,n-s,>2s,^-s
set sw=2
set sts=2
set cindent
set smartindent
set autoindent
break
else
let s:i = s:i + 1
endif
endwhile
endfunction
"command! NoGCCstyle unlet! g:loaded_gcc_style | au! gcc_style
"command! DoGCCstyle runtime gcc_style.vim
let &cpo = s:cpo_save
>indent-by-4 style:
>
> if (act) {
> kact.k_sa_handler = act->sa_handler;
> kact.sa_mask = act->sa_mask.__val[0];
> kact.sa_flags = act->sa_flags;
># ifdef HAVE_SA_RESTORER
> if (kact.sa_flags & SA_RESTORER) {
> kact.sa_restorer = act->sa_restorer;
> } else {
> kact.sa_restorer = choose_restorer (kact.sa_flags);
> kact.sa_flags |= SA_RESTORER;
> }
># endif
> }
I think that the indent-by-4 is the preferred style in uClibc and busybox, fwiw.
>
>Linux kernel style:
>
> if (bufsize > count) {
> bufsize = count;
> if (count == 0) { /* We're at the end of the buffer... */
> __set_errno(EFBIG);
> return -1;
> }
> }
>
>etc.
>
>
>Can you let us know what aspects of style you plan to
>make more uniform, and in what way; what you don't plan
>to regulate.
I'm biased :) The gcc style may not be the most concise but is certainly
quite readable. The indent-by-4 also used in busybox is nice and as we
works well (and we're used to it).
I've seen that some macros exceed the 80th column even with sw=4, which
makes them pretty unreadable. So in my POV it would be ok to change those
if and only if they are our own and _NOT_ inherited from some other source.
>
>For example, how would you write this?
>
> while ((n > 1)
> && ((wi = fgetwc_unlocked(stream)) != WEOF)
> && ((*p++ = wi) != '\n')
> ) {
> --n;
> }
yes, looks ok as would something like
while ((n > 1)
&& (...)
&& ()) {
--n;
}
>
>I promise to not engage in gratuitous style changes,
>there will be no rain of commits with s/spaces/tabs/, :)
>
>I merely plan to follow the agreed-on style in the code
>I touch.
More information about the uClibc
mailing list