在c中使用#ifdef时出现语法错误

时间:2014-11-22 04:22:18

标签: c

我尝试使用和不使用' -D DEBUG'运行以下代码。 gcc flag:

#include <stdio.h>

#ifdef DEBUG
    printf("Defined");
#else
    printf("Not defined");
#endif

int main() 
{
}

我得到的错误是&#34; debugtest.c:6:9:错误:预期的声明说明符或字符串常量前的'...'&#34;

1 个答案:

答案 0 :(得分:3)

您对printf的来电必须 一个功能:

#include <stdio.h>

int main() 
{
#ifdef DEBUG
    printf("Defined");
#else
    printf("Not defined");
#endif
    return 0;    
}