diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-11-19 13:24:34 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-11-20 07:27:37 +0100 |
commit | a98dc693e417bc1a813d5fe1eac663dbbf5ee91c (patch) | |
tree | 13c2f350afe6fc1c53ce2f79263c99e2158ce9b0 /docs/CODING_STYLE.md | |
parent | a527f70a41d96a754ab02915a69b4e4bdea18cc7 (diff) | |
download | systemd-a98dc693e417bc1a813d5fe1eac663dbbf5ee91c.tar.gz |
CODING_STYLE: fix rules for STRLEN and recommend strjoina more strongly
Again, this mostly matches what is happening in the codebase already.
Diffstat (limited to 'docs/CODING_STYLE.md')
-rw-r--r-- | docs/CODING_STYLE.md | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/docs/CODING_STYLE.md b/docs/CODING_STYLE.md index abcdaab4ac..e70c56b766 100644 --- a/docs/CODING_STYLE.md +++ b/docs/CODING_STYLE.md @@ -373,12 +373,16 @@ something some time", or so is a lazy excuse. Always wait for the proper event, instead of doing time-based poll loops. -- To determine the length of a constant string `"foo"`, don't bother - with `sizeof("foo")-1`, please use `STRLEN()` instead. - -- If you want to concatenate two or more strings, consider using - `strjoin()` rather than `asprintf()`, as the latter is a lot - slower. This matters particularly in inner loops. +- To determine the length of a constant string `"foo"`, don't bother with + `sizeof("foo")-1`, please use `strlen()` instead (both gcc and clang optimize + the call away for fixed strings). The only exception is when declaring an + array. In that case use STRLEN, which evalutates to a static constant and + doesn't force the compiler to create a VLA. + +- If you want to concatenate two or more strings, consider using `strjoina()` + or `strjoin()` rather than `asprintf()`, as the latter is a lot slower. This + matters particularly in inner loops (but note that `strjoina()` cannot be + used there). - Please avoid using global variables as much as you can. And if you do use them make sure they are static at least, instead of |