summaryrefslogtreecommitdiff
path: root/CODING_STYLE
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-05-15 15:47:37 +0200
committerLennart Poettering <lennart@poettering.net>2015-05-15 15:47:37 +0200
commit42706f47c918b035dee82f4bad15bf6499592d1c (patch)
tree45fc08bc175e516bf39912367d8901e4d8937cc7 /CODING_STYLE
parent304b3079a2039971db6d89f4557931776b758e41 (diff)
CODING_STYLE: document alloca() DONTS
Diffstat (limited to 'CODING_STYLE')
-rw-r--r--CODING_STYLE12
1 files changed, 11 insertions, 1 deletions
diff --git a/CODING_STYLE b/CODING_STYLE
index 70f45bebb1..00986eb43c 100644
--- a/CODING_STYLE
+++ b/CODING_STYLE
@@ -121,7 +121,8 @@
no speed benefit, and on calls like printf() "float"s get promoted
to "double"s anyway, so there is no point.
-- Do not invoke functions when you allocate variables on the stack. Wrong:
+- Do not mix function invocations with variable definitions in one
+ line. Wrong:
{
int a = foobar();
@@ -259,3 +260,12 @@
which will always work regardless if p is initialized or not, and
guarantees that p is NULL afterwards, all in just one line.
+
+- Use alloca(), but never forget that it is not OK to invoke alloca()
+ within a loop or within function call parameters. alloca() memory is
+ released at the end of a function, and not at the end of a {}
+ block. Thus, if you invoke it in a loop, you keep increasing the
+ stack pointer without ever releasing memory again. (VLAs have better
+ 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.