summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe de Dinechin <dinechin@redhat.com>2018-02-08 12:25:29 +0100
committerFrediano Ziglio <fziglio@redhat.com>2018-02-09 10:11:30 +0000
commitb34478a65242d6f9fdd3aa18abbc118862358ce9 (patch)
tree10869454f6061b11f21eae8d42bc33534f347baf
parent5088afb05a63d1e4b087b631278a64fecfcd5cd6 (diff)
Add mention of header guards
Signed-off-by: Christophe de Dinechin <dinechin@redhat.com> Acked-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r--docs/spice_style.txt19
1 files changed, 19 insertions, 0 deletions
diff --git a/docs/spice_style.txt b/docs/spice_style.txt
index 6fdba48c..0c4fa50d 100644
--- a/docs/spice_style.txt
+++ b/docs/spice_style.txt
@@ -348,6 +348,25 @@ char *array[] = {
"item_3",
};
+Headers
+-------
+
+Headers should be protected against multiple inclusion using a macro that contains the header file name in uppercase, with all characters that are invalid in C replaced with an underscore '_':
+
+[source,c]
+----
+#ifndef MY_MODULE_H
+#define MY_MODULE_H
+
+...
+
+#endif // MY_MODULE_H
+----
+
+The macro may include additional information, e.g. a component. For example a file generally referenced as foo/bar.h could use a FOO_BAR_H macro.
+
+Historically, some headers added underscores liberally, e.g. MY_MODULE_H_. This is neither necessary nor discouraged, although as a reminder, a leading underscore followed by a capital letter is reserved for the implementation and should not be used, so _MY_MODULE_H is, technically speaking, invalid C.
+
Header inclusion
----------------