diff options
| author | David Lamparter <equinox@opensourcerouting.org> | 2019-02-11 11:41:26 +0100 | 
|---|---|---|
| committer | Renato Westphal <renato@opensourcerouting.org> | 2019-02-11 15:49:49 -0200 | 
| commit | be566e4e45aed586716958a1c4adeb00cc352bc0 (patch) | |
| tree | d02f0f1ebdb8a4ca1385fa8a09364ab647ec9b44 /lib/prefix.h | |
| parent | cd2d58525eed81ff60ddbebd78ee2d08398c8f18 (diff) | |
lib: make union prefixptr C++-compatible
Add a no-op conversion constructor to tell C++ that union prefixptr
accepts any of its member types.
Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'lib/prefix.h')
| -rw-r--r-- | lib/prefix.h | 29 | 
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/prefix.h b/lib/prefix.h index aaffb1e0c5..231a407cc8 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -276,20 +276,29 @@ struct prefix_sg {   * side, which strips type safety since the cast will accept any pointer   * type.)   */ +#ifndef __cplusplus +#define prefixtype(uname, typename, fieldname) \ +	typename *fieldname; +#else +#define prefixtype(uname, typename, fieldname) \ +	typename *fieldname; \ +	uname(typename *x) { this->fieldname = x; } +#endif +  union prefixptr { -	struct prefix *p; -	struct prefix_ipv4 *p4; -	struct prefix_ipv6 *p6; -	struct prefix_evpn *evp; -	const struct prefix_fs *fs; +	prefixtype(prefixptr, struct prefix,      p) +	prefixtype(prefixptr, struct prefix_ipv4, p4) +	prefixtype(prefixptr, struct prefix_ipv6, p6) +	prefixtype(prefixptr, struct prefix_evpn, evp) +	prefixtype(prefixptr, struct prefix_fs,   fs)  } __attribute__((transparent_union));  union prefixconstptr { -	const struct prefix *p; -	const struct prefix_ipv4 *p4; -	const struct prefix_ipv6 *p6; -	const struct prefix_evpn *evp; -	const struct prefix_fs *fs; +	prefixtype(prefixconstptr, const struct prefix,      p) +	prefixtype(prefixconstptr, const struct prefix_ipv4, p4) +	prefixtype(prefixconstptr, const struct prefix_ipv6, p6) +	prefixtype(prefixconstptr, const struct prefix_evpn, evp) +	prefixtype(prefixconstptr, const struct prefix_fs,   fs)  } __attribute__((transparent_union));  #ifndef INET_ADDRSTRLEN  | 
