Linux __stringify && __stringify_1__linux

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.