This shows you the differences between two versions of the page.
c:preprocessor:error [2013/10/23 15:44] Awad A. Bekhet [error] |
c:preprocessor:error [2024/02/16 01:06] (current) |
||
---|---|---|---|
Line 6: | Line 6: | ||
==== 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) | ||
#error Syntax to Pass this stage is required ! | #error Syntax to Pass this stage is required ! | ||
Line 14: | Line 41: | ||
===== output of error c example ===== | ===== output of error c example ===== | ||
- | If __"PASS_COMPILER"__ is __not defined__ in program, Then __compilation terminates__ with Error Message as shown: | + | 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> | <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> |