summaryrefslogtreecommitdiffhomepage
path: root/c.html.markdown
diff options
context:
space:
mode:
authorAdam Bard <github@adambard.com>2017-09-12 22:42:18 -0700
committerGitHub <noreply@github.com>2017-09-12 22:42:18 -0700
commita5c23e8af4be114ed5e04c1034acbc6ef4890719 (patch)
tree87cf0e0cadeefbe09fbf39d2dab9f5f25bc71273 /c.html.markdown
parenta6e460618dad10b5962dbd496f8826902fab6eae (diff)
Update c.html.markdown
Note on macro hygiene. Fixes #2853
Diffstat (limited to 'c.html.markdown')
-rw-r--r--c.html.markdown10
1 files changed, 8 insertions, 2 deletions
diff --git a/c.html.markdown b/c.html.markdown
index 1ad0dd53..c47a2df7 100644
--- a/c.html.markdown
+++ b/c.html.markdown
@@ -756,8 +756,14 @@ as the C file.
/* Like c source files macros can be defined in headers and used in files */
/* that include this header file. */
#define EXAMPLE_NAME "Dennis Ritchie"
-/* Function macros can also be defined. */
-#define ADD(a, b) (a + b)
+
+/* Function macros can also be defined. */
+#define ADD(a, b) ((a) + (b))
+
+/* Notice the parenthesis surrounding the arguments -- this is important to */
+/* ensure that a and b don't get expanded in an unexpected way (e.g. consider */
+/* MUL(x, y) (x * y); MUL(1 + 2, 3) would expand to (1 + 2 * 3), yielding an */
+/* incorrect result) */
/* Structs and typedefs can be used for consistency between files. */
typedef struct Node