相关疑难解决方法(0)

是不是有语法错误?应该是printf("一个",两个和""%s.\n","三个"); 是有效的代码?

看看这段代码:

#include <stdio.h>

#define _ONE "one"
#define _TWO_AND ", two and "
int main()
{
    const char THREE[6] = "three" ;
    printf(_ONE _TWO_AND "%s.\n", THREE );
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

printf是有效的:

printf("one" ", two and " "%s.\n", "three" );
Run Code Online (Sandbox Code Playgroud)

输出是:

一,二,三.

gcc编译此代码后既没有错误也没有警告消息.gcc编译器是否应该以这种方式工作,还是一个bug?

c syntax gcc string-literals c-preprocessor

2
推荐指数
1
解决办法
208
查看次数

标签 统计

c ×1

c-preprocessor ×1

gcc ×1

string-literals ×1

syntax ×1