C Language: #warning Directive
This C tutorial explains how to use the #warning preprocessor directive in the C language.
Description
In the C Programming Language, the #warning directive is similar to an #error directive, but does not result in the cancellation of preprocessing. Information following the #warning directive is output as a message prior to preprocessing continuing.
Syntax
The syntax for the #warning directive in the C language is:
#warning message
- message
- The message to output prior to continuing preprocessing.
Example
Let's look at how to use #warning directives in your C program.
The following example shows the output of the #warning directive:
/* Example using #warning directive by TechOnTheNet.com */ #include <stdio.h> int main() { /* The age of TechOnTheNet in seconds */ int age; #warning The variable age may exceed the size of a 32 bit integer /* 12 years, 365 days/year, 24 hours/day, 60 minutes/hour, 60 seconds/min */ age = 12 * 365 * 24 * 60 * 60; printf("TechOnTheNet is %d seconds old\n", age); return 0; }
When compiling this program, the preprocessor will output the following warning:
warning: The variable age may exceed the size of a 32 bit integer
Since this is a #warning directive, the program compilation continues and we can execute the program to see its output.
Here is the output of the executable program:
TechOnTheNet is 378432000 seconds old
Advertisements