Skip to content

Commit

Permalink
portability: Ensure no C99-illegal semicolons exists in structs
Browse files Browse the repository at this point in the history
Macro _OBJECT_TRACING_NEXT_PTR expands to a member or to nothing.
Macro _OBJECT_TRACING_NEXT_PTR is used in a number of places, like:

        struct k_stack {
                .. omitted ..
                _OBJECT_TRACING_NEXT_PTR(k_stack);
                u8_t flags;
        };

When the macro expands to nothing, a lonesome semi would remain. This is
illegal in C99, but permitted in GCC with GNU extensions.

Rather than expand to empty, we now expand to a zero-length array.
This means we can retain the trailing semis across structs wherein the
macro is used.

Note that zero-length array (foo[0]) != flexible array member (foo[]):
 * zero-length array: Is GNU+Clang extension. Anywhere in struct.
 * flexible array member: Is C99. Only in end of struct.

Thus we have really only traded-off one portability issue for
another, more acceptable, one at least.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
  • Loading branch information
mped-oticon authored and nashif committed Sep 28, 2018
1 parent f0e2e1b commit 9960bd9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ typedef struct {
#define _OBJECT_TRACING_INIT .__next = NULL,
#else
#define _OBJECT_TRACING_INIT
#define _OBJECT_TRACING_NEXT_PTR(type)
#define _OBJECT_TRACING_NEXT_PTR(type) u8_t __dummy_next[0]
#endif

#ifdef CONFIG_POLL
Expand Down

0 comments on commit 9960bd9

Please sign in to comment.