C universal macro names - gcc -fextended-identifiers

为君一笑 提交于 2019-12-12 14:36:10

问题


I'm looking for how can I write identifiers name with characters like [ ' " or #.

Everytime that I try to do that, I give the error:

error: macro names must be identifiers

But learning about gcc, I found this option:

-fextended-identifiers

But it seems not working like I wanted, please, somebody know how to accomplish that?


回答1:


Identifiers can't include such characters. It is defined that way in the language syntax, identifiers are letters, digits or underline (and mustn't begin with a digit to avoid ambiguity with litteral numbers).

If it was possible this would conflict with the C compiler (that uses [ for arrays) and C preprocessor syntax (that uses #). Extended identifiers extension only allow using characters non forbidden by the language syntax inside identifiers (basically unicode foreign letters, etc.).

But if you really, really want to do this, nothings forbids you to preprocess your source files with your own "extended macro preprocessor", practically creating a new "C like" language. That looks like a terrible idea, but it's not really hard to do. Then you'll see soon enough by yourself why it's not a good idea...




回答2:


According to this link, -fextended-identifiers only enables UTF-8 support for identifiers, so it won't help in your case.

So, answer is: You can't use such characters in macro identifiers.




回答3:


Even if the extended identifier characters support was fully enabled, it wouldn't help you get characters such as:

[ ' " #

enabled for identifiers. The standard allows 'universal character names' or 'other implementation-defined characters' to be part of an identifier, but they cannot be part of the basic character set. Out of the basic character set, only _, letters and digits can be part of an identifier name (6.4.2.1 Identifiers/General).



来源:https://stackoverflow.com/questions/4739776/c-universal-macro-names-gcc-fextended-identifiers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!