糖尿病康复,内容丰富有趣,生活中的好帮手!
糖尿病康复 > boolean mct_object_set_parent(mct_object_t *object mct_object_t *parent) 有感

boolean mct_object_set_parent(mct_object_t *object mct_object_t *parent) 有感

时间:2019-10-27 11:05:00

相关推荐

boolean mct_object_set_parent(mct_object_t *object  mct_object_t *parent) 有感

高通 mct 里面充斥了宏#define MCT_OBJECT_CAST(obj) ((mct_object_t*)(obj)),对mct_object_t 的调用的理解可以最简单的参考如下的代码,mct_object_t 是如何在不同的结构体传递。

#include <stdio.h>#include <stdlib.h>#include <malloc.h>typedef struct _mct_object mct_object_t;typedef struct _mct_stream mct_stream_t;typedef struct _mct_module mct_module_t;struct _mct_object {unsigned intparentsnum;unsigned intchildrennum;char* name;};struct _mct_module {mct_object_tobject;unsigned int numsrcports;};struct _mct_stream {mct_object_tobject;unsigned int streamid;unsigned int frmaeid;;};void mct_object_set_parent(mct_object_t *object, mct_object_t *parent){object->name = parent->name;object->parentsnum = parent->parentsnum;object->childrennum = parent->childrennum;printf("stream %p module %p\n",object,parent);}int main(){mct_stream_t* stream = (mct_stream_t *)malloc(sizeof(mct_stream_t));mct_module_t* module = (mct_module_t *)malloc(sizeof(mct_module_t));printf("stream %p module %p\n",stream,module);module->numsrcports = 1;module->object.parentsnum = 1;module->object.childrennum = 1;module->object.name = "module";stream->streamid = 2;stream->frmaeid = 2;stream->object.parentsnum = 2;stream->object.childrennum = 2;stream->object.name= "stream";printf("stream->object.parentsnum=%d stream->object.childrennum=%d stream->object.name=%s\n",stream->object.parentsnum,stream->object.childrennum,stream->object.name);mct_object_set_parent((mct_object_t*)stream,(mct_object_t*)module);printf("stream->object.parentsnum=%d stream->object.childrennum=%d stream->object.name=%s\n",stream->object.parentsnum,stream->object.childrennum,stream->object.name);printf("stream %p module %p\n",stream,module);free(stream);free(module);return 0;}

打印 log 如下

stream 0x20fd010 module 0x20fd030stream->object.parentsnum=2 stream->object.childrennum=2 stream->object.name=streamstream 0x20fd010 module 0x20fd030stream->object.parentsnum=1 stream->object.childrennum=1 stream->object.name=modulestream 0x20fd010 module 0x20fd030

如果觉得《boolean mct_object_set_parent(mct_object_t *object mct_object_t *parent) 有感》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。