This shows you the differences between two versions of the page.
|
c:preprocessor:error [2013/02/03 19:16] 127.0.0.1 external edit |
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 ==== | ||
| - | error is in work by code-reference.com \\ | + | The #error directive emits a user-specified error message at compile time and then terminates the compilation. |
| - | if you are faster... don't hasitate and add it | + | 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> | ||
| - | no example at the moment | + | #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) | ||
| + | #error Syntax to Pass this stage is required ! | ||
| + | #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> | ||