Accesing shm structure using pointer

梦想与她 提交于 2019-12-25 08:03:14

问题


I have a c structure like this :

struc str{
  int values[10];
}str

In a posix so like fedora i copied this structure to a part of shared memory (shm_open, ftruncate, mmap and memcpy) and I got a pointer to structure from shm. Now how do I change a value in the values array by using this pointer (*ptr).

Imagine i want to do str->values[5] = 10; how to I do that using the pointer.


回答1:


Just use the pointer:

struct str *p = ptr;
p->values[5] = 10;


来源:https://stackoverflow.com/questions/8077884/accesing-shm-structure-using-pointer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!