diff options
| author | David Lamparter <equinox@diac24.net> | 2021-02-21 06:18:10 +0100 |
|---|---|---|
| committer | David Lamparter <equinox@diac24.net> | 2021-03-17 06:18:17 +0100 |
| commit | bf8d3d6aca3f20255a621ed1c148fd05b3a8ae5c (patch) | |
| tree | cd62a7c64fe8eb9f3252e1b608f1fb939c2a772c /lib/memory.h | |
| parent | 15c05f1edf079bc03b277e44426a8af8616bb10b (diff) | |
*: require semicolon after DEFINE_MTYPE & co
Back when I put this together in 2015, ISO C11 was still reasonably new
and we couldn't require it just yet. Without ISO C11, there is no
"good" way (only bad hacks) to require a semicolon after a macro that
ends with a function definition. And if you added one anyway, you'd get
"spurious semicolon" warnings on some compilers...
With C11, `_Static_assert()` at the end of a macro will make it so that
the semicolon is properly required, consumed, and not warned about.
Consistently requiring semicolons after "file-level" macros matches
Linux kernel coding style and helps some editors against mis-syntax'ing
these macros.
Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib/memory.h')
| -rw-r--r-- | lib/memory.h | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/memory.h b/lib/memory.h index e9db12fce2..c95602f485 100644 --- a/lib/memory.h +++ b/lib/memory.h @@ -56,20 +56,20 @@ struct memgroup { /* macro usage: * * mydaemon.h - * DECLARE_MGROUP(MYDAEMON) - * DECLARE_MTYPE(MYDAEMON_COMMON) + * DECLARE_MGROUP(MYDAEMON); + * DECLARE_MTYPE(MYDAEMON_COMMON); * * mydaemon.c - * DEFINE_MGROUP(MYDAEMON, "my daemon memory") + * DEFINE_MGROUP(MYDAEMON, "my daemon memory"); * DEFINE_MTYPE(MYDAEMON, MYDAEMON_COMMON, - * "this mtype is used in multiple files in mydaemon") + * "this mtype is used in multiple files in mydaemon"); * foo = qmalloc(MTYPE_MYDAEMON_COMMON, sizeof(*foo)) * * mydaemon_io.c * bar = qmalloc(MTYPE_MYDAEMON_COMMON, sizeof(*bar)) * * DEFINE_MTYPE_STATIC(MYDAEMON, MYDAEMON_IO, - * "this mtype is used only in this file") + * "this mtype is used only in this file"); * baz = qmalloc(MTYPE_MYDAEMON_IO, sizeof(*baz)) * * Note: Naming conventions (MGROUP_ and MTYPE_ prefixes are enforced @@ -78,7 +78,7 @@ struct memgroup { * but MGROUP_* aren't. */ -#define DECLARE_MGROUP(name) extern struct memgroup _mg_##name; +#define DECLARE_MGROUP(name) extern struct memgroup _mg_##name #define _DEFINE_MGROUP(mname, desc, ...) \ struct memgroup _mg_##mname \ __attribute__((section(".data.mgroups"))) = { \ @@ -104,7 +104,7 @@ struct memgroup { _mg_##mname.next->ref = _mg_##mname.ref; \ *_mg_##mname.ref = _mg_##mname.next; \ } \ - /* end */ + MACRO_REQUIRE_SEMICOLON() /* end */ #define DEFINE_MGROUP(mname, desc) \ _DEFINE_MGROUP(mname, desc, ) @@ -112,7 +112,7 @@ struct memgroup { _DEFINE_MGROUP(mname, desc, .active_at_exit = true) #define DECLARE_MTYPE(name) \ - extern struct memtype MTYPE_##name[1]; \ + extern struct memtype MTYPE_##name[1] \ /* end */ #define DEFINE_MTYPE_ATTR(group, mname, attr, desc) \ @@ -140,7 +140,7 @@ struct memgroup { MTYPE_##mname->next->ref = MTYPE_##mname->ref; \ *MTYPE_##mname->ref = MTYPE_##mname->next; \ } \ - /* end */ + MACRO_REQUIRE_SEMICOLON() /* end */ #define DEFINE_MTYPE(group, name, desc) \ DEFINE_MTYPE_ATTR(group, name, , desc) \ @@ -150,8 +150,8 @@ struct memgroup { DEFINE_MTYPE_ATTR(group, name, static, desc) \ /* end */ -DECLARE_MGROUP(LIB) -DECLARE_MTYPE(TMP) +DECLARE_MGROUP(LIB); +DECLARE_MTYPE(TMP); extern void *qmalloc(struct memtype *mt, size_t size) |
