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.
原文地址:https://www.cnblogs.com/lumao1122-Milolu/p/13277560.html