Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 使用指针访问shm结构_C_Memory_Pointers_Structure_Shared - Fatal编程技术网

C 使用指针访问shm结构

C 使用指针访问shm结构,c,memory,pointers,structure,shared,C,Memory,Pointers,Structure,Shared,我有这样一个c结构: struc str{ int values[10]; }str 在类似fedora的posix中,我将此结构复制到共享内存的一部分(shm_open,ftruncate,mmap和memcpy),并从shm获得了指向该结构的指针。现在,我如何使用这个指针(*ptr)更改值数组中的值 假设我想做str->values[5]=10;如何使用指针来执行此操作 只需使用指针: struct str *p = ptr; p->values[5] = 10;

我有这样一个c结构:

struc str{
  int values[10];
}str
在类似fedora的posix中,我将此结构复制到共享内存的一部分(
shm_open
ftruncate
mmap
memcpy
),并从shm获得了指向该结构的指针。现在,我如何使用这个指针(*ptr)更改值数组中的值

假设我想做str->values[5]=10;如何使用指针来执行此操作

只需使用指针:

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