From bf8d3d6aca3f20255a621ed1c148fd05b3a8ae5c Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Sun, 21 Feb 2021 06:18:10 +0100 Subject: *: 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 --- lib/compiler.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/compiler.h') diff --git a/lib/compiler.h b/lib/compiler.h index b5cfbefeb5..ab95aa09c0 100644 --- a/lib/compiler.h +++ b/lib/compiler.h @@ -136,6 +136,9 @@ extern "C" { #define macro_inline static inline __attribute__((unused)) #define macro_pure static inline __attribute__((unused, pure)) +/* if the macro ends with a function definition */ +#define MACRO_REQUIRE_SEMICOLON() \ + _Static_assert(1, "please add a semicolon after this macro") /* variadic macros, use like: * #define V_0() ... -- cgit v1.2.3