给定以下结构体:
struct PipeShm
{
int init;
int flag;
sem_t *mutex;
char * ptr1;
char * ptr2;
int status1;
int status2;
int semaphoreFlag;
};
那很好用:
static struct PipeShm myPipe = { .init = 0 , .flag = FALSE , .mutex = NULL ,
.ptr1 = NULL , .ptr2 = NULL , .status1 = -10 , .status2 = -10 ,
.semaphoreFlag = FALSE };
但是当我声明 static struct PipeShm * myPipe
时,它不起作用,我假设我需要使用运算符->
进行初始化,但如何操作?
static struct PipeShm * myPipe = {.init = 0 , .flag = FALSE , .mutex = NULL ,
.ptr1 = NULL , .ptr2 = NULL , .status1 = -10 , .status2 = -10 ,
.semaphoreFlag = FALSE };
是否可以声明一个指向结构体的指针并对其进行初始化?