Linux Driver Development--__stringify

Source: Internet
Author: User

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

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.