This shows you the differences between two versions of the page.
|
c:preprocessor:error [2013/10/23 15:23] Awad A. Bekhet [description of error] |
c:preprocessor:error [2024/02/16 01:06] (current) |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== error ====== | ====== error ====== | ||
| <code c> | <code c> | ||
| + | #error your error_message | ||
| </code> | </code> | ||
| ==== description of error ==== | ==== description of error ==== | ||
| The #error directive emits a user-specified error message at compile time and then terminates the compilation. | The #error directive emits a user-specified error message at compile time and then terminates the compilation. | ||
| + | The following code will cause in compilation error: | ||
| + | <code c> | ||
| + | #include<stdio.h> | ||
| + | int main() | ||
| + | { | ||
| + | printf("code-reference.com/c"); | ||
| + | |||
| + | return 0; | ||
| + | } | ||
| + | |||
| + | #if !defined(PASS_COMPILER) | ||
| + | #error Syntax to Pass this stage is required ! | ||
| + | #endif | ||
| + | </code> | ||
| + | The following code will compile: | ||
| <code c> | <code c> | ||
| + | #define PASS_COMPILER /*You can write this definition here or any*/ | ||
| + | #include<stdio.h> | ||
| + | |||
| + | int main() | ||
| + | { | ||
| + | printf("code-reference.com/c"); | ||
| + | |||
| + | /*#define PASS_COMPILER*/ | ||
| + | |||
| + | return 0; | ||
| + | } | ||
| + | |||
| #if !defined(PASS_COMPILER) | #if !defined(PASS_COMPILER) | ||
| - | //<fc #FF0000>#error</fc> <fc #0000FF>C++ compiler required.</fc>// | + | #error Syntax to Pass this stage is required ! |
| #endif | #endif | ||
| </code> | </code> | ||
| ===== output of error c example ===== | ===== output of error c example ===== | ||
| - | no example at the moment | + | In first program: |
| + | No output, because __"PASS_COMPILER"__ is __not defined__ in program, so __compilation terminates__ with Error Message as shown: | ||
| + | <fc #FF0000>//"\main.c|4|error: #error Syntax to Pass this stage is required !|"//</fc> | ||
| + | In the Second program: | ||
| + | Output will be: | ||
| + | <code> | ||
| + | code-reference.com/c | ||
| + | </code> | ||