There is a macro __stringify in the Linux kernel, which is defined in Include/linux/stringify.h as follows:
#ifndef __linux_stringify_h #define __linux_stringify_h/* Indirect stringification. Doing levels allows the parameter to be a * macro itself. */ #define __stringify_1 (x ...) #x#define __stringify (x ...) __stringify_1 (x)#endif/ *!__linux_stringify_h */
The effect is actually to convert the x directly to a string. The return value is a string, not a variable name.
Usage 1:
#define __attr (_name,_mode,_show,_store) {/ = {. Name = __stringify (_name),. Mode = _mode},/ c9/>= _show, / = _store, / }
Suppose we use __attr this way:
__attr (Var_name, 777, show_function, store_function)
Then, the value that is actually copied to the. Attr.name is "Var_name" instead of the value represented by the Var_name variable.
Usage 2: Convert an enumeration type to a string
#define Wcd_mbhc_stringify (s) __stringify (s)
enum wcd_notify_event { wcd_event_invalid, /**/ wcd_event_pre_ Micbias_2_off, Wcd_event_post_micbias_2_off, wcd_event_pre_micbias_2_on, Wcd_event_post_micbias _2_ON,
Static Const Char*wcd_mbhc_get_event_string (int Event){ Switch(Event) { CaseWcd_event_pre_micbias_2_off:returnwcd_mbhc_stringify (Wcd_event_pre_micbias_2_off); CaseWcd_event_post_micbias_2_off:returnwcd_mbhc_stringify (Wcd_event_post_micbias_2_off); Casewcd_event_pre_micbias_2_on:returnWcd_mbhc_stringify (wcd_event_pre_micbias_2_on);
Linux Driver Development--__stringify