summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2015-10-29 15:03:55 +0100
committerWerner Koch <wk@gnupg.org>2015-10-29 15:03:55 +0100
commit965486031bd094bd017c3eba9b53cf7b1e3ab6a8 (patch)
treead22cc6f07184618a011142cb335aaca64975063 /doc
parentgpg: Display the correct error message. (diff)
downloadgnupg2-965486031bd094bd017c3eba9b53cf7b1e3ab6a8.tar.xz
gnupg2-965486031bd094bd017c3eba9b53cf7b1e3ab6a8.zip
Use of some C99 features is now permitted.
-- Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'doc')
-rw-r--r--doc/HACKING42
1 files changed, 41 insertions, 1 deletions
diff --git a/doc/HACKING b/doc/HACKING
index 5d720172f..2f3dd43a0 100644
--- a/doc/HACKING
+++ b/doc/HACKING
@@ -123,11 +123,51 @@ Note that such a comment will be removed if the git commit option
need. If you really need to do it, use a separate commit for such a
change.
- - C99 syntax should not be used; stick to C90.
+ - Only certain C99 features may be used (see below); in general
+ stick to C90.
- Please do not use C++ =//= style comments.
- Try to fit lines into 80 columns.
- Ignore signed/unsigned pointer mismatches
- No arithmetic on void pointers; cast to char* first.
+ - We use our own printf style functions like =es_printf=, and
+ =es_asprintf= which implement most C99 features with the exception
+ of =wchar_t= (which should anyway not be used). Please always use
+ them and do not resort to those provided by libc. The rationale
+ for using them is that we know that the format specifiers work on
+ all platforms and that we do not need to chase platform dependent
+ bugs.
+ - It is common to have a label named "leave" for a function's
+ cleanup and return code. This helps with freeing memory and is a
+ convenient location to set a breakpoint for debugging.
+ - Always use xfree() instead of free(). If it is not easy to see
+ that the freed variable is not anymore used, explicitly set the
+ variable to NULL.
+ - Init function local variables only if needed so that the compiler
+ can do a better job in detecting uninitialized variables which may
+ indicate a problem with the code.
+ - Never init static or file local variables to 0 to make sure they
+ end up in BSS.
+ - Use --enable-maintainer-mode with configure.
+
+*** C99 language features
+
+ In GnuPG 2.x, but *not in 1.4* and not in most libraries, a limited
+ set of C99 features may be used:
+
+ - Variadic macros:
+ : #define foo(a,...) bar(a, __VA_ARGS__)
+
+ - The predefined macro =__func__=:
+ : log_debug ("%s: Problem with foo\n", __func__);
+
+ - Variable declaration inside a for():
+ : for (int i = 0; i < 5; ++)
+ : bar (i);
+
+ Although we usually make use of the =u16=, =u32=, and =u64= types,
+ it is also possible to include =<stdint.h>= and use =int16_t=,
+ =int32_t=, =int64_t=, =uint16_t=, =uint32_t=, and =uint64_t=. But do
+ not use =int8_t= or =uint8_t=.
** Commit log keywords