Re: [RFC] Use plan9 C extensions
From: Rasmus Villemoes
Date: Thu Jan 10 2019 - 05:34:47 EST
On 10/01/2019 00.55, Nick Desaulniers wrote:
> I agree that something like builtin_types_compatible_p() in a macro
> could help make these functions more "generic" in the sense of being
> able to accept either a `struct xarray*` or `struct xarray_cyclic*`.
An alternative to implementing all the generic functions as macros is
transparent_union:
https://godbolt.org/z/TK_SJD
If there is an interface that takes a "const xarray *" one would define
another union type
union __transparent_union const_xarray_any {
const struct xarray *xa;
const struct xarray_cyclic *xac;
};
The obvious implementation using _Generic fails since all expressions
must be valid:
https://godbolt.org/z/X0bvwO
and _Generic is gcc >= 4.9 anyway. I think an implementation based on
choose_expr/types_compatible might have the same problem, but maybe
there's some clever way around that.
Rasmus