xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: David Vrabel <david.vrabel@citrix.com>
To: xen-devel@lists.xensource.com
Cc: Keir Fraser <keir@xen.org>, David Vrabel <david.vrabel@citrix.com>
Subject: [PATCH] Document the current coding style conventions.
Date: Wed, 14 Mar 2012 17:27:18 +0000	[thread overview]
Message-ID: <1331746038-25892-1-git-send-email-david.vrabel@citrix.com> (raw)

From: David Vrabel <david.vrabel@citrix.com>

Based on a version originally posted in 2007.
http://lists.xen.org/archives/html/xen-devel/2007-06/msg00070.html

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
---
 docs/misc/coding_style.txt |  100 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 100 insertions(+), 0 deletions(-)
 create mode 100644 docs/misc/coding_style.txt

diff --git a/docs/misc/coding_style.txt b/docs/misc/coding_style.txt
new file mode 100644
index 0000000..2ece1ec
--- /dev/null
+++ b/docs/misc/coding_style.txt
@@ -0,0 +1,100 @@
+Coding Style for the Xen Hypervisor
+===================================
+
+This coding style is used for C code that is part of the Xen
+Hypervisor itself, or part of the associated user space tools.  Guest
+operating system code may use the native coding style of that code
+base.  The goal of this file is to document the main points of the Xen
+coding style, particularly where they differ from normal Linux
+convention.
+
+libxl has its own coding style documented in tools/libxl/CODING_STYLE.
+
+Indentation
+-----------
+
+Indenting uses spaces, not tabs - in contrast to Linux.  An indent
+level consists of four spaces.  Code within blocks is indented by one
+extra indent level.  The enclosing braces of a block are indented the
+same as the code _outside_ the block.  e.g.
+
+void fun(void)
+{
+    /* One level of indent. */
+
+    {
+        /* A second level of indent. */
+    }
+}
+
+White space
+-----------
+
+Space characters are used to spread out logical statements, such as in
+the condition of an if or while.  Spaces are placed between the
+keyword and the brackets surrounding the condition, between the
+brackets and the condition itself, and around binary operators (except
+the structure memory operators, '.' and '->'). e.g.
+
+if ( (wibble & wombat) == 42 )
+{
+    ...
+
+There should be no trailing white space at the end of lines (including
+after the opening /* of a comment block).
+
+Bracing
+-------
+
+Braces ('{' and '}') are usually placed on a line of their own, except
+for the do/while loop.  This is unlike the Linux coding style and
+unlike K&R.  do/while loops are an exception. e.g.:
+
+if ( condition )
+{
+    /* Do stuff. */
+}
+
+while ( condition )
+{
+    /* Do stuff. */
+}
+
+do {
+    /* Do stuff. */
+} while ( condition );
+
+etc.
+
+Braces should be omitted for blocks with a single statement. e.g.,
+
+if ( condition )
+    single_statement();
+
+Comments
+--------
+
+Only C style /* ... */ comments are to be used.  C++ style // comments
+should not be used in submitted code.  Multi-word comments should
+begin with a capital letter and end with a full stop.
+
+/*
+ * Example, multi-line comment block.
+ *
+ * Note beginning and end markers on separate lines and leading '*'.
+ */
+
+Emacs local variables
+---------------------
+
+A comment block containing local variables for emacs is permitted at
+the end of files.  It should be:
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
-- 
1.7.2.5

             reply	other threads:[~2012-03-14 17:27 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-14 17:27 David Vrabel [this message]
2012-03-15  9:11 ` [PATCH] Document the current coding style conventions Jan Beulich
2012-03-15  9:34 ` Ian Campbell
2012-03-15 10:54   ` David Vrabel
2012-03-15 11:07     ` Ian Campbell
2012-03-19 11:18   ` David Vrabel
2012-03-19 11:23     ` Ian Campbell
2012-03-15 18:23 ` Dario Faggioli
2012-03-16  9:23   ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1331746038-25892-1-git-send-email-david.vrabel@citrix.com \
    --to=david.vrabel@citrix.com \
    --cc=keir@xen.org \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).