3

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?

tshepang
  • 12,111
  • 21
  • 91
  • 136
drigoSkalWalker
  • 2,742
  • 9
  • 32
  • 45
  • 2
    Look here http://stackoverflow.com/questions/369495/what-are-the-valid-characters-for-macro-names – Elalfer Jan 19 '11 at 19:39
  • 4
    This seems like an absolutely terrible idea. What is the underlying problem you're trying to solve? If you can explain why you'd want to do this, maybe we can help you find a less evil way of accomplishing it. – Jim Lewis Jan 19 '11 at 19:40
  • I'm looking to write identifiers name with such characters only this, but using only C prerpocessor, thanks for your feedback – drigoSkalWalker Jan 19 '11 at 19:45
  • 1
    A language that accepts `[`, `'`, `"`, or `#` in identifiers is not C. So you cannot do what you want in C (see Standard 6.4.2.1). – pmg Jan 19 '11 at 21:24

3 Answers3

2

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 literal 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, nothing 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...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kriss
  • 23,497
  • 17
  • 97
  • 116
1

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.

schnaader
  • 49,103
  • 10
  • 104
  • 136
  • Yes, but [ ' " is part of UTF-8 sort, don't it? – drigoSkalWalker Jan 19 '11 at 19:45
  • 1
    It's not part of the *additional* characters that come with UTF-8. The point is, all of the characters you want have a meaning for the compiler already while UTF-8 characters aren't used for any statements, operators or similar compiler things. – schnaader Jan 19 '11 at 19:48
  • 2
    And that FAQ indicates that even 'native' UTF-8 isn't directly supported - only `\uNNNN` or `\UNNNNNNNN` 'universal' characters are supported - you have to run your source through a filter to convert 'native' extended characters to the universal notation. – Michael Burr Jan 19 '11 at 20:06
0

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Michael Burr
  • 333,147
  • 50
  • 533
  • 760