Hash :
c504bec0
Author :
Date :
2022-09-13T17:29:35
assert-h: static_assert is a keyword in C23 * m4/assert_h.m4 (gl_ASSERT_H): Also test for static_assert keyword a la C23, and define HAVE_C_STATIC_ASSERT if so. If not, arrange for config.h to #define static_assert by including <assert.h>, and then do "#undef assert" so that the assert macro still needs an explicit include. This should be safe even on very old hosts, as assert.h has been re-includable for decades. * tests/tests-assert.c: New test. * modules/assert-h-tests (Files, Makefile.am): Add it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
@node assert.h
@section @file{assert.h}
POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/assert.h.html}
Gnulib module: assert-h
See also the Gnulib modules @code{assert} and @code{verify}.
Portability problems fixed by Gnulib:
@itemize
@item
On older C platforms @code{<assert.h>} must be included before using
@code{static_assert}. For example, GCC versions before 13 do not
support the @code{static_assert} keyword that was standardized by C23.
@item
On older platforms @code{static_assert} does not allow the second
string-literal argument to be omitted. For example, GCC versions
before 9.1 do not support the single-argument @code{static_assert}
that was standardized by C23 and C++17.
@item
Even-older platforms do not support @code{static_assert} at all.
For example, GCC versions before 4.6 and G++ versions before 4.3
do not support the two-argument form, which was standardized
by C11 and C++11.
@item
Older C platforms might not support the obsolescent
@code{_Static_assert} keyword or macro.
This portability problem should not matter with code using this
module, as such code should use @code{static_assert} instead.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
@item
A @code{static_assert} can also
be used within a @code{struct} or @code{union} specifier, in place of
an ordinary declaration of a member of the struct or union. The
Gnulib substitute can be used only as an ordinary declaration
in code intended to be portable to C99 or earlier.
@item
In C23 and C++11 and later, @code{static_assert} is a keyword.
In C11 and C17 it is a macro. Any Gnulib substitute is also a macro.
@item
In C99 and later, @code{assert} can be applied to any scalar expression.
In C89, the argument to @code{assert} is of type @code{int}.
@end itemize