Search code examples
c#unity-game-engineundef

Seeming evaluation of preprocessor code inside a #if false block


I'm working in C# via MonoDevelop 4.0.1 (Current version for Unity), and have hit a seeming language weirdness.

Here's my entire .cs file:

#if false

#define foo

#endif

class myClass {
  int member;
}

#if false

#error this error does not trigger

#undef foo
// "cannot define or undefine preprocessor symbols after first token in file

#endif

I understand the rule about not #undefing a preprocessor symbol after a token has been declared, but in this case i'm not #undefing because the #undef is inside a #if false.

This example is not entirely contrived, it's an attempt to get a single source file to compile in both C# and C++ via the approach described here.


Solution

  • Visual Studio doesn't complain about the same code. I think you have discovered a bug in Mono.