Commit a24cf746 authored by Simon McVittie's avatar Simon McVittie
Browse files

internals: Use Standard C offsetof macro if available

clang 13 fails to compile our current implementation with:

.../dbus/dbus-message.c:2070:3: error: variable length array folded to constant array as an extension [-Werror,-Wgnu-folding-constant]
.../dbus/dbus-internals.h:460:25: note: expanded from macro '_DBUS_STATIC_ASSERT'
  typedef struct { char _assertion[(expr) ? 1 : -1]; } \

This appears to be because the "traditional" definition of
offsetof(), which we're hard-coding here, does not qualify as a constant
expression under C rules due to its use of pointer casts.

Modern compilers like gcc and clang have a built-in implementation
of offsetof that *is* a constant expression.

Signed-off-by: Simon McVittie's avatarSimon McVittie <>
parent 83232393
Pipeline #464990 passed with stage
in 7 minutes and 4 seconds
......@@ -193,8 +193,13 @@ void _dbus_real_assert_not_reached (const char *explanation,
#define _DBUS_ZERO(object) (memset (&(object), '\0', sizeof ((object))))
#ifdef offsetof
#define _DBUS_STRUCT_OFFSET(struct_type, member) \
(offsetof (struct_type, member))
#define _DBUS_STRUCT_OFFSET(struct_type, member) \
((intptr_t) ((unsigned char*) &((struct_type*) 0)->member))
#define _DBUS_ALIGNOF(type) \
(_DBUS_STRUCT_OFFSET (struct { char _1; type _2; }, _2))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment