In the C traps and defects, when implementing assert, the author skillfully processes the process and converts the process into an expression using the features of logic or operators, when the condition is false, _ assert_error is called to report an error and terminate the program.
The returned value type of _ assert_error is void. Therefore, in (void) (e) | _ assert_error (_ file __, _ line __))) an error occurs: The Void value is not ignored as expected, although exit (-1) does not force the type of Return Value of the function, however, when void is forcibly ignored, the exception is detected (what is the cause ??).
1 # include <stdio. h>
2 # include <stdlib. h>
3 # include <math. h>
4
5 # define assert (e )\
6 (void) (e) | _ assert_error (_ file __, _ line __)))
7 // {If (! (E) assert_error (_ file __, _ line __);}
8
9 int _ assert_error (char * filename, int line ){
10 printf ("error ouccurred in % s at line: % d \ n", filename, line );
11 exit (-1 );
12}
13
14
15 int main (){
16 int flag = 1;
17 int y =-8;
18 if (FLAG)
19 assert (Y> 0 );
20 else printf ("hhhhhhhhh \ n ");
21 printf ("% F \ n", SQRT (y ));
22 // printf ("test, % s -- % d \ n", _ file __, _ line __);
23
24 return 0;
25}