cpp problem: unterminated arg list

Robert Lipe robertlipe@usa.net
Thu Oct 19 16:54:00 GMT 2000

We have some code that (ab)uses the preprocessor to synthesize vararg
macros that have stopped working with GCC.  I can't spot it as a known
outtage in http://gcc.gnu.org/proj-cpplib.html .  Personally, I'd be
delighted to be able to use either GCC or C99 variants of same, but
this code has to work on C89 compliant compilers.  It has worked on
GCC for some time (egcs 1.1.2, GCC 2.95) and works on compilers from
Sun, SCO, Intel, and others.  (I'm not foolish enough to think makes
the code legal. :-) I can't spot anything non-conforming, but I'm not
Mr. Preprocessor.

Here's a testcase:

$ cat z.c
#define _VA_ARGS_0()
#define _ARG_VARS_0
#define _ARG_LIST_0()
#define _MP_ARGS_0
#define _L_0()                      (
#define _R_0()                      )

#define __VA_ARGLIST(argc,list) \
                _VA_ARGS_##argc list

#define _CAT_LIST(argc,list1,list2) \
                _L_##argc list1 _R_##argc list2

#define _VA_ARGLIST(argc,list1,list2) \
                __VA_ARGLIST(argc, \
                        _CAT_LIST(argc, list1, list2))

#define BLAH(a) _VA_ARGLIST(a, (), ())


When built with the top-of-tree GCC, this reports:

$ /tmp/negcs/gcc/xgcc -B/tmp/negcs/gcc/ -c z.c
z.c:22:9: unterminated argument list for macro "_VA_ARGS_0"

Any ideas why this is failing?

Thanx for any help.

More information about the Gcc-bugs mailing list