From 343cd13e17062eb024f45b44036d930988bd0299 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 11 Feb 2019 16:04:26 -0200 Subject: lib: add macro that performs explicit static casts when using a C++ compiler C++ doesn't support implicit casts from void pointers like C does. And the libfrr headers have some bits of code that rely on implicit casts in order to work. To solve this problem, add a new "static_cast" macro that performs explicit static casts when a C++ compiler is being used, or do nothing otherwise. NOTE: since macros are only evaluated when they are used, there might be other macros from libfrr that will need to use "static_cast" as well. If a header is successfully compiled using a C++ compiler, there's no guarantee that its macros are compatible with C++. We'll only know about such macros when they are used by C++ code, then we'll need to adapt them one by one in the future. Signed-off-by: Renato Westphal --- lib/zebra.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/zebra.h') diff --git a/lib/zebra.h b/lib/zebra.h index 43ab4309c2..b96fb5a206 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -232,6 +232,15 @@ typedef unsigned char uint8_t; #include "zassert.h" +/* + * Add explicit static cast only when using a C++ compiler. + */ +#ifdef __cplusplus +#define static_cast(l, r) static_cast((r)) +#else +#define static_cast(l, r) (r) +#endif + #ifndef HAVE_STRLCAT size_t strlcat(char *__restrict dest, const char *__restrict src, size_t destsize); -- cgit v1.2.3