Книга: C# 2008 Programmer
#warning and #error
#warning and #error
The #warning
preprocessor directive lets you generate a warning from a specific location of your code. The following example shows how you can use it to display warning messages during compilation time.
for (int i = 1; i <= num; i++) {
//---sum up all odd numbers---
if (i % 2 == 1) {
sum += i;
#if DEBUG
#warning Debugging mode is on
Console.WriteLine("i={0}, sum={1}", i, sum);
#elif NORMAL
#warning Normal mode is on
Console.WriteLine("sum={0}", sum);
#else
#warning Default mode is on
Console.WriteLine(".");
#endif
}
}
Figure 3-16 shows the output when the DEBUG
symbol is defined using the /define
compiler option.
Figure 3-16
The #error
preprocessor directive lets you generate an error. Consider the following example:
for (int i = 1; i <= num; i++) {
//---sum up all odd numbers---
if (i % 2 == 1) {
sum += i;
#if DEBUG
#warning Debugging mode is on
Console.WriteLine("i={0}, sum={1}", i, sum);
#elif NORMAL
#error This mode is obsolete.
Console.WriteLine("sum={0}", sum);
#else
#warning Default mode is on
Console.WriteLine(".");
#endif
}
}
Here, if the NORMAL
symbol is defined, an error message is shown and the statement defined within the conditional directive is ignored. Figure 3-17 shows that when you define the NORMAL
symbol, the error message is displayed and the compilation is aborted.
Figure 3-17
- Разработка приложений баз данных InterBase на Borland Delphi
- Open Source Insight and Discussion
- Introduction to Microprocessors and Microcontrollers
- Chapter 6. Traversing of tables and chains
- Chapter 8. Saving and restoring large rule-sets
- Chapter 11. Iptables targets and jumps
- Chapter 5 Installing and Configuring VirtualCenter 2.0
- Chapter 16. Commercial products based on Linux, iptables and netfilter
- Appendix A. Detailed explanations of special commands
- Appendix B. Common problems and questions
- Appendix E. Other resources and links
- IP filtering terms and expressions