aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-05-15 21:06:40 +0200
committerLennart Poettering <lennart@poettering.net>2015-05-15 21:06:40 +0200
commita5ecb0cec25befafdee1e32c6f24cda8e29f89af (patch)
tree231dd9ab75fa01a78ceb220a9db389d1e4230ce1 /CODING_STYLE
parentcoredump: make sure we vacuum by default (diff)
downloadsystemd-a5ecb0cec25befafdee1e32c6f24cda8e29f89af.tar.gz
systemd-a5ecb0cec25befafdee1e32c6f24cda8e29f89af.tar.bz2
systemd-a5ecb0cec25befafdee1e32c6f24cda8e29f89af.zip
CODING_STYLE: document best practices when initializing structs
Diffstat (limited to 'CODING_STYLE')
-rw-r--r--CODING_STYLE18
1 files changed, 18 insertions, 0 deletions
diff --git a/CODING_STYLE b/CODING_STYLE
index 00986eb43..795521cc6 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";