Hydrargyrum
Hydrargyrum

Reputation: 3806

What naming constraints apply to C# conditional compilation symbols?

What rules apply to the names of conditional compilation symbols in C#?

I've consulted the #define documentation, the /define compiler switch documentation, and the C# language specification. The #define and /define docs just say that you can define a symbol name, and that symbol names don't conflict with variable names. The language spec says that there is a "conditional-symbol" token, but doesn't appear to comment on what constitutes a valid symbol token - I might not be looking in quite the right place?

EDIT: a link to authoritative documentation would be useful

Upvotes: 3

Views: 259

Answers (1)

BoltClock
BoltClock

Reputation: 723538

The symbol definition can be found in section 2.5.1 of the spec:

2.5.1 Conditional compilation symbols

The conditional compilation functionality provided by the #if, #elif, #else, and #endif directives is controlled through pre-processing expressions (§2.5.2) and conditional compilation symbols.

conditional-symbol:
Any identifier-or-keyword except true or false

This is reflected online in the same section and in the grammar under §C.1.10, but note that the spec that's available online is for a very old version of the language and should not be used as a reference. You can find the latest available spec in C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC#\Specifications\1033 or for download (it's still C# 5.0 as of this writing, apparently).

The definition of identifier-or-keyword can be found in §B.1.6 Identifiers.

Upvotes: 3

Related Questions