用于定义字符串的引用宏

Quote macro for defining string

是否可以引用宏的"content"? 类似于以下用于打印字符串 "AAA".

的代码
#include <stdio.h>
#include <stdlib.h>

#define _L 5
#define _QUOTE(a) #a
#define _TEXT AAA
#define _STRINGAAA _QUOTE(_TEXT)

const char STRINGAAA[ _L ] = _STRINGAAA;

int main(void)
{
    printf( "%s\n", STRINGAAA );
    return EXIT_SUCCESS;
}

您需要使用第二组宏在字符串化之前强制替换宏参数:

#include <stdio.h>
#include <stdlib.h>

#define _L 5
#define _XQUOTE(a) #a
#define _QUOTE(a) _XQUOTE(a)
#define _TEXT AAA
#define _STRINGAAA _QUOTE(_TEXT)

const char STRINGAAA[ _L ] = _STRINGAAA;

int main(void)
{
    printf( "%s\n", STRINGAAA );
    return EXIT_SUCCESS;
}