#if 0 causing a Unity 2018.2.2f1 freeze on Mac OS X

Coming from a C and C++ background with very little knowledge of C# and being very new to Unity, I tried to comment out some code with an #if 0 preprocessor directive, just like I’m used to do in C and C++.

This caused Unity 2018.2.2f1 to freeze under Mac OS X 10.13.6.

Is this a known feature, a bug, or what? If it is a bug, where can I check if has already been reported? If it has not been reported, how do I report it.

Context: I’m porting dbus-csharp (GitHub - steffen-kiess/dbus-sharp: DBus Sharp) to Unity, in order to connect Unity to BlueZ under Linux, for BlueTooth communication.

Pre-processor directives work different in C# than in C / C++. While the C / C++ preprocessor allows you to actually define macros / arbitrary replacement symbols, including other files, provide line meta data and to define conditional compilation sections, the C# compiler is more limited. In C# you don’t have an actual preprocessor but the directives are handled by the compiler directly.

In C / C++ a define is basically just a replacement value / macro. However in C# a define is just a symbolic name that doesn’t have a value. The #if statement does not allow numeric values, only define symbols. The condtions are restricted to pure boolean logic. So you could just use

#if false
// never included
#endif

#if true
// always included
#endif

But you can also use any symbol that isn’t defined like

#if ThisWillNeverBeDefined
 ...
#endif

Note that conditional compilation was never meant to comment out a section of code “manually”. For this you can use block comments. Conditional compilation can be used when you have a configuration switch which defines which behaviour should be used