A few days ago I saw a macro, and it was probably like this:
#define ASSERT_PARAM (expr) (expr)? (void) 0:assert_failed ((U8 *) __file__, __line__))
The meaning of the code is simple, the key is the use of that (void) 0, I was the first time to see
When I use void, there are two things:
1. Put in front of the function, emphasizing that the function has no return value, that is, the function cannot be the right value
such as: void fun (int x);
2. Place the function parameter inside, emphasizing that the function has no parameters
such as: int fun (void);
Another usage is:
#define NULL ((void*) 0)
This is, of course, the way null NULL pointers are defined (inside stdlib.h).
But, above the macro (void) 0, at first it really made me feel a little strange, do not know what to do, calm down and think about.
It turns out that the purpose of the macro is to prevent the macro from being used as an rvalue, and (void) 0 cannot itself be the right value, because void is not a real type!
C language (void*) 0 and (void) 0