首页 > 其他 > 详细

define a struct

时间:2020-07-10 10:40:27      阅读:53      评论:0      收藏:0      [点我收藏+]

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.

 

define a struct

原文:https://www.cnblogs.com/lumao1122-Milolu/p/13277560.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!