开发者

C universal macro names - gcc -fextended-identifiers

开发者 https://www.devze.com 2023-02-05 08: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:

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?


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...


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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消