Skip to content

Detect compiler support for transparent unions

Tony Finch requested to merge fanf-transparent-unions into fanf-atomic-lists

When we are using an inheritance pattern, where several structures share a common prefix, we would like it to be easy to pass any of these subtype structures to functions that only operate on the common prefix, but we would also like it to be type safe.

A simple way is to use void pointers, because they can be freely assigned without explicit casts, but this isn't type safe. We can use _Generic macros to dispatch based on subtype, but that can be quite ugly and awkward.

This change adds an ISC_ATTR_TRANSPARENT macro to indicate when we can use GNU C transparent unions. Transparent unions have quiet conversions like void pointers, but only for a specific set of types. On compilers without transparent unions we can use void pointers instead; we still benefit from type checking during development.

Merge request reports