mirror of
https://github.com/systemd/systemd.git
synced 2024-12-18 06:33:36 +08:00
CODING_STYLE: document best practices when initializing structs
This commit is contained in:
parent
5470c03b37
commit
a5ecb0cec2
18
CODING_STYLE
18
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";
|
||||
|
Loading…
Reference in New Issue
Block a user