From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvSYb-0003e5-J2 for qemu-devel@nongnu.org; Wed, 07 Oct 2009 05:11:37 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvSYX-0003bS-5S for qemu-devel@nongnu.org; Wed, 07 Oct 2009 05:11:37 -0400 Received: from [199.232.76.173] (port=48766 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvSYX-0003bD-0A for qemu-devel@nongnu.org; Wed, 07 Oct 2009 05:11:33 -0400 Received: from mail2.shareable.org ([80.68.89.115]:58166) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MvSYW-0002eb-LM for qemu-devel@nongnu.org; Wed, 07 Oct 2009 05:11:32 -0400 Date: Wed, 7 Oct 2009 10:11:27 +0100 From: Jamie Lokier Subject: Re: [Qemu-devel] [PATCH] CODING_STYLE: {} as in linux kernel Message-ID: <20091007091126.GB12384@shareable.org> References: <20091006190115.GA4768@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20091006190115.GA4768@redhat.com> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: Blue Swirl , qemu-devel@nongnu.org Michael S. Tsirkin wrote: > 4. Block structure > > -Every indented statement is braced; even if the block contains just one > -statement. The opening brace is on the line that contains the control > -flow statement that introduces the new block; the closing brace is on the > -same line as the else keyword, or on a line by itself if there is no else > -keyword. Example: > +If an indented block contains just one statement, it is not braced. This > +matches the Linux coding style. The opening brace of a block is on the line > +that contains the control flow statement that introduces the new block; the > +closing brace is on the same line as the else keyword, or on a line by itself > +if there is no else keyword. Example: > > - if (a == 5) { > + if (a == 5) > printf("a was 5.\n"); > - } else if (a == 6) { > + else if (a == 6) { > printf("a was 6.\n"); > - } else { > + printf("multiply by 7 to get the answer.\n"); > + } else > printf("a was something else entirely.\n"); > - } > > An exception is the opening brace for a function; for reasons of tradition > and clarity it comes on a line by itself: > @@ -75,4 +75,5 @@ and clarity it comes on a line by itself: > > Rationale: a consistent (except for functions...) bracing style reduces > ambiguity and avoids needless churn when lines are added or removed. > +This matches the linux coding style. Actually the above does not match the Linux coding style, and it's ugly too. This is the Linux style: Do not unnecessarily use braces where a single statement will do. if (condition) action(); This does not apply if one branch of a conditional statement is a single statement. Use braces in both branches. if (condition) { do_this(); do_that(); } else { otherwise(); } -- Jamie