[PATCH weston] sdk: make C++11 plugins build again
Thiago Macieira
thiago.macieira at intel.com
Mon Dec 9 18:40:51 PST 2013
On segunda-feira, 9 de dezembro de 2013 15:57:16, Kristian Høgsberg wrote:
> Ugh, ok, sorry. Maybe we need a private header file where we can hide
> all our C macros - ARRAY_LENGTH, static_assert, container_of etc.
This "poor man's static_assert" should work in C99 mode too:
#include <assert.h>
#if !defined(static_assert) && (!defined(__cplusplus) || __cplusplus < 201103L)
# define static_assert(cond, msg) enum { \
CONCAT(_static_assert_, __COUNTER__) = sizeof(char[(cond) ? 1 : -1]) \
};
#endif
For proper CONCAT defined elsewhere.
Or, for a public header:
#include <assert.h>
#if defined(static_assert) || (defined(__cplusplus) && __cplusplus >= 201103L)
# define wl_static_assert(cond) static_assert(cond, #cond)
#else
# define wl_static_assert(cond) enum { \
CONCAT(_static_assert_, __COUNTER__) = sizeof(char[(cond) ? 1 : -1]) \
};
#endif
For failed assertions, it will produce:
C89, C99, C++98:
error: array size is negative
C11, C++11:
error: static_assert failed "fail"
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20131209/1e1b6fed/attachment.pgp>
More information about the wayland-devel
mailing list