3
#define UPUT_SET_CHECK_POINT1(appType, tag, argNum1, v1, ...)  \

if(NUMARGS(##__VA_ARGS__) == 0)           \
UPUT_SET_CHECK_POINTx(1, appType, tag,  argNum1, v1,  UPUT_P_INVALID, 0, UPUT_P_INVALID, 0, UPUT_P_INVALID, 0, UPUT_P_INVALID, 0, __FILE__, __LINE__, UPUT_SEQUENTIAL);                   \
else                                     \
UPUT_SET_CHECK_POINTx(1, appType, tag,  argNum1, v1,  UPUT_P_INVALID, 0, UPUT_P_INVALID, 0, UPUT_P_INVALID, 0, UPUT_P_INVALID, 0, __FILE__, __LINE__ , __VA_ARGS__) 

so when VA_ARGS is empty I am getting a compile time error "expected primary-expression before ')' token". Any way to fix the compilation error.

void UPUT_SET_CHECK_POINTx(int numArg, CtblAppType appType, int tag, UputArgPos argNum1, int v1, UputArgPos argNum2, int v2, UputArgPos argNum3, int v3, UputArgPos argNum4, int v4, UputArgPos argNum5, int v5, char* fileName, unsigned int lineNumber, UputCheckPointAlgo checkPointAlgo=UPUT_SEQUENTIAL);
Flexo
  • 87,323
  • 22
  • 191
  • 272
Pawan
  • 71
  • 1
  • 8
  • 3
    Can't you just do it with templates instead? – Flexo May 07 '12 at 11:00
  • 2
    Seems a rather compilcated and unreadable way of doing whatever you are trying to do. There would be a simpler, type safe and easier to read solution. – Ed Heal May 07 '12 at 11:02
  • UPUT_SET_CHECK_POINT1 was a function which is present in 2 thousand files and I don't want to touch that files so I thought to make it to macro and replacing with a function UPUT_SET_CHECK_POINTx – Pawan May 07 '12 at 11:03
  • @PawanKumarSrivastava - you can still do that just as well with templates most likely – Flexo May 07 '12 at 11:14

1 Answers1

10

If you are using GCC, you could use , ## __VA_ARGS__ to eliminate the comma when __VA_ARGS__ is empty.

#define UPUT_SET_CHECK_POINT1(appType, tag, argNum1, v1, ...)  \
    UPUT_SET_CHECK_POINTx(1, appType, tag,  argNum1, v1, \
                          UPUT_P_INVALID, 0, \
                          UPUT_P_INVALID, 0, \
                          UPUT_P_INVALID, 0, \
                          UPUT_P_INVALID, 0, \
                          __FILE__, __LINE__ , ## __VA_ARGS__)

See also Standard alternative to GCC's ##__VA_ARGS__ trick?. There's no standard workaround to this if you have to use preprocessors.

Community
  • 1
  • 1
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005