简体   繁体   English

Unicode 在 C 预处理器中定义语句

[英]Unicode define statements in C preprocessor

I was doing some testing and fiddling about and noticed the C preprocessor does not let me use unicode with the define directive.我正在做一些测试和摆弄,并注意到 C 预处理器不允许我将 unicode 与 define 指令一起使用。 Below is an example of my plight.以下是我的困境的一个例子。

#include <stdio.h>

#define φαντασία fancy

int main() {
        printf("Is the C preprocessor φαντασία?");
}

It is giving me this output...它给了我这个 output...

$ ./a.out 
Is the C preprocessor φαντασία?

Is there some way to fix this behaviour, it seems worthy of a feature request perhaps.有什么方法可以解决此问题,这似乎值得一个功能请求。 Have I done something wrong?我做错了什么吗?

Preprocessor replacement doesn't work on text;预处理器替换不适用于文本; it works on tokens .它适用于令牌 When your printf line is processed, text is converted to 5 tokens first:处理printf行时,文本首先转换为 5 个标记:

  1. identifier token printf标识符令牌printf
  2. punctuator token (标点符号(
  3. string-literal token "Is the C preprocessor φαντασία?" string-literal token "Is the C preprocessor φαντασία?"
  4. punctuator token )标点符号)
  5. punctuator token ;标点符号;

Only identifier type tokens are considered by macro replacement system.宏替换系统仅考虑标识符类型标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM