[systemd-commits] CODING_STYLE

Lennart Poettering lennart at kemper.freedesktop.org
Fri May 15 12:07:19 PDT 2015


 CODING_STYLE |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

New commits:
commit a5ecb0cec25befafdee1e32c6f24cda8e29f89af
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri May 15 21:06:40 2015 +0200

    CODING_STYLE: document best practices when initializing structs

diff --git a/CODING_STYLE b/CODING_STYLE
index 00986eb..795521c 100644
--- a/CODING_STYLE
+++ b/CODING_STYLE
@@ -269,3 +269,21 @@
   behaviour in this case, so consider using them as an alternative.)
   Regarding not using alloca() within function parameters, see the
   BUGS section of the alloca(3) man page.
+
+- Use memzero() or even better zero() instead of memset(..., 0, ...)
+
+- Instead of using memzero()/memset() to initialize structs allocated
+  on the stack, please try to use c99 structure initializers. It's
+  short, prettier and actually even faster at execution. Hence:
+
+          struct foobar t = {
+                  .foo = 7,
+                  .bar = "bazz",
+          };
+
+  instead of:
+
+          struct foobar t;
+          zero(t);
+          t.foo = 7;
+          t.bar = "bazz";



More information about the systemd-commits mailing list