On Tuesday 02 December 2008 08:28, Carmelo AMOROSO wrote:
> > Hi Bernhard, folks,
> > 
> > Can you indicate what coding style you prefer
> > in uclibc?
> 
> Hi Denys,
> my preferred style is kernel's one, I don't think uclibc has
> a preferred one, even if, yesy, a Coding style rules could be useful.

Mine too.

> > For example, how would you write this?
> > 
> >         while ((n > 1)
> >                    && ((wi = fgetwc_unlocked(stream)) != WEOF)
> >                    && ((*p++ = wi) != '\n')
> >                    ) {
> >                 --n;
> >         }
>
> I'd write as follow:
> 
> while ((n > 1) && ((wi = fgetwc_unlocked(stream)) != WEOF)
>       && ((*p++ = wi) != '\n')) {
>       --n;
> }

I usually avoid assignments in conditions altogether.
Well, small ones like "while ((arg = *argv++) != NULL) {...}"
are not too bad, but the one in that example
is really not readable. I'd convert second and third parts
of && into separate "if(xx) break" statements in the while()
body. Who cares that it will be a bit larger, it will be
easier to parse for readers of our code, _that_ is more important.

Look at this gem in test/regex/testregex.c:

if (!(ans = setlocale(LC_COLLATE, s)) || streq(ans, "C") || streq(ans, "POSIX") 
|| !(ans = setlocale(LC_CTYPE, s)) || streq(ans, "C") || streq(ans, "POSIX"))

--
vda
_______________________________________________
uClibc mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/uclibc

Reply via email to