Home  >  Q&A  >  body text

c++ - A question about static syntax

I will try my best to describe the problem clearly. If there is anything unclear, please leave a message and I will reply as soon as possible.
The following statement form is available:

 typedef struct mr_dup_ops
    {
        /* 查询镜像状态 */
        int32_t (*dup_mirror_state_query)(uint32_t, mr_kern_mirror_state_query_req_t*);
        ……………………
        ……………………
      
    } mr_dup_owner_ops_t;

Then declare

STATIC mr_dup_owner_ops_t g_local_mr_dup_ops = {
    .dup_mirror_state_query        = mr_ioctl_kern_mirror_state_query,
    ………………
    ………………
    };

Then assuming there is a pointer ops of mr_dup_owner_ops_t, you can access the function mr_ioctl_kern_mirror_state_query through ops->dup_mirror_state_query.

I can understand that the structure mr_dup_owner_ops_t declares a set of function pointers, then add the STATIC structure. Structure name ={.dup_mirror_state_query. What form is this?

習慣沉默習慣沉默2690 days ago955

reply all(3)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-06-30 09:58:42

    Just declare the scope of the variable g_local_mr_dup_ops to be static. What macro should STATIC be? The keywords in C/C++ are in lowercase.

    reply
    0
  • 学习ing

    学习ing2017-06-30 09:58:42

    static structure A variable a = { ..... }

    Define a variable a of type A, static attribute, and initialize it using {....}

    reply
    0
  • 天蓬老师

    天蓬老师2017-06-30 09:58:42

    The syntax of the initialization part is an extension of gcc, called Designated Initializers.

    reply
    0
  • Cancelreply