Table of Contents

error

#error your error_message

description of error

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:

#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

The following code will compile:

#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

output of error c example

In first program: No output, because “PASS_COMPILER” is not defined in program, so compilation terminates with Error Message as shown: “\main.c|4|error: #error Syntax to Pass this stage is required !|”

In the Second program: Output will be:

code-reference.com/c