## __VA_ARGS__ in binutils-gdb?

Nick Alcock nick.alcock@oracle.com
Thu Nov 20 16:18:46 GMT 2025


So I have a use case inside libctf where it looks like variadic macros
might be useful (souping it up so that all errors emit natural-language
text into the error/warning stream, in service to reducing the number of
ECTF_ constants to a sane number now we don't need to rely on them to
disambiguate which function call failed).

I'm trying to do this while keeping the number of translatable strings
down, ideally by keeping the strings the same for the same errors coming
from different functions, but including the name of the function that
failed in the output, so I can say (e.g. in ctf_add_decl_tag()):

  ctf_err_type (fp, type, ECTF_RANGE,
	        _("component index %i greater than member count %lu"),
	        component_idx, ctf_member_count (fp, type));

and have it emit this into the err/warning stream:

  ctf_add_decl_tag (".BTF", 0x402): component index 42 greater than member count 6: argument out of range

or, for something in which no extra info is needed, we can eschew the
translatable string entirely and simplify right down, e.g. this from
ctf_add_member_bitfield():

  ctf_err_type (fp, type, ECTF_INCOMPLETE, NULL);

which emits (for a type in a child dict derived from foo/bar.c):

  ctf_add_member_bitfield ("foo/bar.c", 0x392): type is not a complete type

(where "type is not a complete type" is what ctf_errmsg() returns for
ECTF_INCOMPLETE).

Now obviously the key here is the function name, and I really don't want
to have to type __func__ in everywhere. So that means a variadic macro.
But ## __VA_ARGS__ is a GCC-specific compiler extension, and all
hackarounds for its absence are either horrifying (HAS_COMMA) or too new
to rely on (__VA_OPT__).

So I was surprised to find ## __VA_ARGS__ in use in binutils-gdb with no
configure tests or ifdeffery guarding it; mostly in GDB but also in some
arch-dependent parts of BFD. So I'm wondering... is ## __VA_ARGS__
widely enough available that I can use it in libctf? People using
strange compilers without this GCC extension can always disable libctf,
but if such compilers are actually still commonplace this would make me
rather queasy. (I suspect they're rare as anything.)

(Apologies if this has come up before: it's really hard to search for.)


More information about the Binutils mailing list