Linux has a stringify header file, the main contents of which are as follows:
#ifndef __linux_stringify_h
#define __LINUX_STRINGIFY_H/
* Indirect stringification. Doing two levels allows the parameter to be a
* macro itself. For example, compile With-dfoo=bar, __stringify (FOO)
* converts to "bar".
* *
#define __STRINGIFY_1 (x ...) #x
#define __STRINGIFY (x ...) __stringify_1 (x)
#endif/ *!__linux_stringify_h * *
There are two define in it, which is not quite clear according to the annotation. Why should the middle pass through __stringify_1 to convert? Direct use of #define __STRINGIFY (x ...) #x岂不是更加简洁.
Programming Test:
#include <stdio.h>
#define Triple-a BBB
#define __STRINGIFY_1 (x.) #x
#define __STRINGIFY (x.) __ Stringify_1 (x)
#define __STRINGIFY_SRC (x ...) #x
main ()
{
printf ("Stringify (AAA): %s\n", __stringify (AAA));
printf ("Stringify_src (AAA):%s\n", __STRINGIFY_SRC (AAA));
}
The results of the operation are as follows:
Stringify (AAA): BBB
STRINGIFY_SRC (AAA): AAA
Then go back and look at the notes.
But there's this sentence in the comment "doing two levels allows the parameter to be a macro itself."
How to understand it.
If you define a #define BBB CCC before #define AAA BBB, #define CCC DDD ..., how is the result of this program running?
Oh, we can try.