define a struct

how to use a macro of structure ? 

Here I am listing  steps for it by using a demo:

  1. macro a structure:
    #define structed_define                              \
            {                                       \
              "this is a demo for structed",1883        \
            }
    structed_define

    this is a macro for structure.

  2. define a structure class:
    typedef struct_static
    {
        char* name;
        int port;
    } xi_static_host_desc_t;
    struct_static

    this is a structure class

  3. define a const class which is using the structure:  #define XI_MQTT_HOST_ACCESSOR ( ( xi_static_host_desc_t )structed_define) 
  4. assign buffer and int :
    unsigned int b;
    char buf[32];
    b=XI_MQTT_HOST_ACCESSOR.port;
    memcpy(buf,XI_MQTT_HOST_ACCESSOR.name,strlen(XI_MQTT_HOST_ACCESSOR.name));

    End

  5. Note.

 

posted on 2020-07-10 09:21  Milo_lu  阅读(146)  评论(0编辑  收藏  举报

导航