formula420
asked on
How to make macros that expand to other special macros (##__VA_ARGS__)
I have some code that I share between visual c++ 2005 and gcc. Within the code, there are a few variadic macros. The problem I have is in the different way gcc and vs handle variadic macro argument lists. VS correctly formats the argument list automatically (inserting leading commas when necessary) by simply using __VA_ARGS__. In gcc, however, ##__VA_ARGS__ is required if a leading comma is needed.
To deal with this, I was just going to write something like this
#ifdef WIN32
#define VA_ARGS __VA_ARGS__
#else
#define VA_ARGS ##__VA_ARGS__
#endif /* WIN32*/
When I compile the code in VS, it seems to work fine. However, gcc gives these errors
/mnt/backupdrive1/Programm ing/pmc_li bs/pmc.c:2 9:17: '##' cannot appear at either end of a macro expansion
/mnt/backupdrive1/Programm ing/pmc_li bs/pmc.c:2 9:19: warning: __VA_ARGS__ can only appear in the expansion of a C99 variadic macro
How can I get the desired result? I appreciate any help
To deal with this, I was just going to write something like this
#ifdef WIN32
#define VA_ARGS __VA_ARGS__
#else
#define VA_ARGS ##__VA_ARGS__
#endif /* WIN32*/
When I compile the code in VS, it seems to work fine. However, gcc gives these errors
/mnt/backupdrive1/Programm
/mnt/backupdrive1/Programm
How can I get the desired result? I appreciate any help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER