[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] Re: style question



Dave Allan <dallan redhat com> wrote:
> Jim Meyering wrote:
>> Finally, I moved a couple variable declarations
>> down (C99-style) to their points of first use.
>
> I take it that the C++/C99 is the recommended style for all libvirt
> code?  I generally haven't coded this way in the past (in fact I
> usually compile with -Wdeclaration-after-statement), and not seeing
> anything in HACKING about it, I continued to use the traditional
> style, but if this way is what everyone's converging on, I'll change
> to it.

Until a couple years ago, the de-facto standard in libvirt (like many
projects) was to use C89-style all-declarations-at-opening-brace, but
since no reasonable portability target lacks a C99 compiler, we are
slowly modernizing with the addition of new code.  If you would like
a long list of reasons for using this aspect of C99, let me know.

Last night I was peeved to have to deal with a pointless conflict because
a declaration-addition evoked a conflict.  Guess why?  Because adding
it at the beginning of the function conflicted with another change that
had also appended to that "function-global" list, but for a different
variable name.  Ironically, both were for uses that were much farther down
and very local, so putting the respective declarations near their uses
would have made the patches and code smaller and more readable,
in addition to avoiding my conflict.

I propose mention in HACKING that it is permitted (encouraged, even) to
use C99 decls-after-stmt, but that you won't get dinged (yet) for using
the old style.  IME, readability and maintainability are important enough
to require minimum distance between decl and first use of each variable,
but others may have different habits and resist the change.  Let's see.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]