当前位置: 技术问答>linux和unix
Linux下的一个指针类型,不懂了,
来源: 互联网 发布时间:2016-04-15
本文导语: struct country{ int mum; }; int *countnum; char *shm_addr; struct country* cont; shm_addr=(cha *)shmat(shm_id,NULL,0); cont = (struct country*)((void*)shm_addr+sizeof(int)); 最后一句是什么意思,好像是初始化的,但是初始化的是什么...
struct country{
int mum;
};
int *countnum;
char *shm_addr;
struct country* cont;
shm_addr=(cha *)shmat(shm_id,NULL,0);
cont = (struct country*)((void*)shm_addr+sizeof(int));
最后一句是什么意思,好像是初始化的,但是初始化的是什么,搞不太清楚,而且在linux编译时提示:“从不兼容的指针类型赋值”。
搞不明白是什么意思,该如何改正呢。
int mum;
};
int *countnum;
char *shm_addr;
struct country* cont;
shm_addr=(cha *)shmat(shm_id,NULL,0);
cont = (struct country*)((void*)shm_addr+sizeof(int));
最后一句是什么意思,好像是初始化的,但是初始化的是什么,搞不太清楚,而且在linux编译时提示:“从不兼容的指针类型赋值”。
搞不明白是什么意思,该如何改正呢。
|
“从不兼容的指针类型赋值” 应该是指这一句吧:shm_addr=(cha *)shmat(shm_id,NULL,0); 改为
shm_addr=(char *)shmat(shm_id,NULL,0);
cont = (struct country*)((void*)shm_addr+sizeof(int));
这一句的意思是:指针 cont 指向 shm_addr 向后偏移 sizeof(int) 个字节的地址。
shm_addr=(char *)shmat(shm_id,NULL,0);
cont = (struct country*)((void*)shm_addr+sizeof(int));
这一句的意思是:指针 cont 指向 shm_addr 向后偏移 sizeof(int) 个字节的地址。
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。