结构体指针转换成int报错

无烟无酒亦无妞 2014-12-25 09:10:53


typedef struct META {
char* name; // the name of member
uint16_t type; // member type
uint16_t offset; // offset of member from the type head
union {
struct META* meta; // support the child struct type
int count; // indicate the count of member when the member is a array type
};
char* alias; // alias for the parameter, use the "name" if this is NULL
} META;

static void valueConvert(struct jsonStruct* message, struct META* meta, void* data)
{
int count = 0;
count = (int)meta->meta; /*如何才能使得本行不报错cast from pointer to integer of different size*/
.........
}
...全文
495 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fly_dragon_fly 2014-12-26
  • 打赏
  • 举报
回复

typedef struct META {
    char* name;        // the name of member
    uint16_t type;    // member type
    uint16_t offset; // offset of member from the type head
    union {
        struct META* meta; // support the child struct type
        int count;    // indicate the count of member when the member is a array type
    } M;
    #define count M.count;
    #define meta  M.meta;
    char* alias; // alias for the parameter, use the "name" if this is NULL
} META;

语句改为 count =meta->count
只是权宜之计,最好还是不要这宏,直接写 meta->M.count
二进制加减法 2014-12-25
  • 打赏
  • 举报
回复
union { struct META* meta; // support the child struct type int count; // indicate the count of member when the member is a array type }; 这是个联合体 如果你想取里面count的值 要改成meta->count count = (int)meta->meta;把结构体指针强转成int型肯定会出错

69,336

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧