C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Then: We can use #if directives in the rest of the file to detect whether a #define was specified.
Here: The program shows that #if PERL will evaluate to true. But #if PYTHON will not.
If: We conditional directives, such as "if" and "elif," and we test the values of our definitions.
C# program that uses define, preprocessor directives
#define PERL
using System;
class Program
{
static void Main()
{
#if PERL
Console.WriteLine(true);
#endif
#if PYTHON
Console.WriteLine(false);
#endif
}
}
Output
True
So: If you know about a warning and it just annoys you, pragma can help. Sometimes this helps with an unused code warning.
However: The pragma directive seems, in my experience, just to add further complexity to an issue that is already complex.
Caution: Other organizational constructs are often better. For example, consider using extra classes or methods to break up your code.
And: Even if the code works, it will not have been tested. Things become more difficult, more dangerous for the programmer.
Bit rot: In large programs, this is a serious issue. Code becomes neglected and might stop working. But in its neglect, we don't know this.
Unreachable: With the pragma directive, we can keep unused code compiling with no warnings. This might help reduce bit rot.
UnreachableQuote: A preprocessing directive always occupies a separate line of source code and always begins with a "#" character and a preprocessing directive name (The C# Programming Language).
Quote: The preprocessor is a relatively unsophisticated macro processor that works primarily on lexical tokens (The C++ Programming Language).