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
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/wayland-devel