|
From: Matthias S. <zz...@ge...> - 2015-03-28 20:04:28
|
On 28.03.2015 19:46, Florian Krohm wrote:
>
> C++'s static_assert cannot be used on file scope either.
c++'s static_assert and C's _Static_assert can be used at file scope.
As far as I could find out, they are declarations and so are allowed
inside functions, stucts, classes and blocks (including file scope in
and out of namespaces).
I tried it and it works quite nice:
#define STATIC_ASSERT(expr) _Static_assert(expr, "failed")
I added a bogus check, and the error message looks nicer:
In file included from pub_core_basics.h:40:0,
from m_cache.c:32:
../include/pub_tool_basics.h:380:1: error: static assertion failed: "failed"
STATIC_ASSERT(1==2);
^
The only missing piece is how to detect availability of this keyword.
Maybe a check for the gcc version is enough here.
Matthias
|