C预处理器宏有2个参数问题

时间:2017-07-27 17:10:48

标签: c macros c-preprocessor preprocessor preprocessor-directive

我的C代码中有这个宏:

#define ASSERT(ret, num) \  // make sure ret === num
        if (ret != num) { \
            fprintf(stderr, "Error [%d] at line [%d] in function [%s]. Date: [%s] Time: [%s]\n", \
                    ret, __LINE__, __FUNCTION__, __DATE__, __TIME__); \
            exit(ret); \
        }

然后我这样称呼它(所有参数都是整数):

ASSERT(errNo, MPI_SUCCESS);
ASSERT(aliveNeighbors, 8);
ASSERT(newGrid, !NULL);

我收到错误(GCC v5.4):

expected identifier or ‘(’ before ‘if’
   if (ret != num) { \
error: stray ‘\’ in program
   ASSERT(errNo, MPI_SUCCESS);
error: stray ‘\’ in program
  ASSERT(aliveNeighbors, 8);
stray ‘\’ in program
  ASSERT(newGrid, !NULL);

这里有什么问题?

0 个答案:

没有答案