chiark / gitweb /
Improve checking for C99-style varargs macros.
This is a rather sad story. C99 introduced `variadic macros'
(gratuitously incompatible with GCC's better thought-out existing
feature for doing the same thing). GCC implements the feature, and
enables it by default. Unfortunately, GCC doesn't declare conformance
with C99 by default (by defining `__STDC_VERSION__' appropriately), so
the naïve test doesn't actually work unless you give GCC some extra
options.
Now that we have a place for `preliminary utilities' in the header file,
define a new macro `SOD__HAVE_VARARGS_MACROS' to report the feature's
availability to generated code, and use this to guard definitions which
make use of the feature.
Apparently (https://gcc.gnu.org/c99status.html) the feature was added to
GCC in version 2.95; I'm testing for version three or later because it's
easy. But this isn't enough. If GCC isn't fully committed to the C99
feature set, then `-pedantic' mode will issue warnings about the use of
variadic macros. Normally we could suppress these with some hacking
involving `__extension__' or `#pragma GCC diagnostic', but GCC's
preprocessor isn't clever enough to deal with any of that. Instead, we
reach for the big hammer and have header files declare themselves to be
`system headers', which means that GCC stops trying to warn about them
at all.
This is really quite a long way from being an ideal situation.