I'm trying to figure out if there's any way to avoid getting an "Unreachable code" warning for something that's caused by the preprocessor. I don't want to suppress all such warnings, only those which will be dependent on the preprocessor, e.g.
#if WINDOWS
public const GamePlatform platform = GamePlatform.PC;
#else
public const GamePlatform platform = GamePlatform.MAC;
#endif
And later on there's code that goes:
if (platform == GamePlatform.PC)
{
...
}
else
{
...
}
One of those two sections will always be detected as "Unreachable code", and we've got those all over the place. I'd like to try and get rid of the many warnings it creates, but I still want to get warnings for legitimately unreachable code. (In reality, there's more than just two platforms, so each chunk of platform-specific code creates a pile of unnecessary warnings.)
Option 1: Add the preprocessor macros wherever you have the if-statements. This will be more performant, but perhaps a bit uglier.
Option 2: Make the platform variable not const. Setting it to static readonly made the warning go away for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With