]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
CODING_STYLE: document best practices when initializing structs
authorLennart Poettering <lennart@poettering.net>
Fri, 15 May 2015 19:06:40 +0000 (21:06 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 15 May 2015 19:06:40 +0000 (21:06 +0200)
CODING_STYLE

index 00986eb43c3fd436162d5ba73f283e51b6011203..795521cc6a6226d3d3a87549b6875ae3075819d4 100644 (file)
   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";