Home > Software design >  Use another char than # in preprocessor directives
Use another char than # in preprocessor directives

Time:10-21

Is there a way to use another char than # when defining preprocessor directives? Example:

Instead of:

#if 1
foo
#endif

Use ?, for example:

?if 1
foo
?endif

CodePudding user response:

You have two options:

  • Trigraphs: ??=if 1
  • Digraphs: %:if 1

Both of these are 100% standard C, but at the same time considered very bad practice. However, mainstream compilers tend to warn against trigraphs but not for digraphs, so digraphs are perhaps the lesser evil.

CodePudding user response:

There are trigraph sequences that exists to replace certain characters. In particular, the # character can be replaced with ??=. So the following code is valid:

??=if 1
foo
??=endif

You can't however put an arbitrary replacement in place.

  • Related