c - mmap and struct (incompatible type error struct to void *) -
i'm getting error:
error: incompatible types when assigning type ‘struct sharedmem’ type ‘void *’
when trying mmap struct sharedmemory. here's i'm trying do:
//struct each card typedef struct card{ char c[3]; //card char s; //suit } card; //struct player information typedef struct player{ int num; char* nickname; char* fifo_p; struct card* hand; } player; //struct sharedmemory typedef struct sharedmem{ unsigned int nplayers; unsigned int dealer; struct player *players; unsigned int roundnumber; unsigned int turn; struct card *tablecards; } sharedmem;
then have function does:
int createsharedmemory(char* shmname,int nplayers){ int shmfd; char shmname[100]={'\0'}; char *ps; ps=&shmname[0]; strcat(ps,"/"); strcat(ps,shmname); // name = /shmname shmfd = shm_open(shmname,o_rdwr,0755); if (shmfd<0){ if (errno==2){ //file or directory not exist (shared memory space not created, meaning it's first process, create shmspace) shmfd = shm_open(shmname,o_creat|o_rdwr,0755); if (shmfd<0){ perror("failure in shm_open()"); fprintf(stderr,"error: %d\n",errno); exit(exit_failure); } } else { perror("failure in shm_open()"); fprintf(stderr,"error: %d\n",errno); exit(exit_failure); } } struct sharedmem shm; // shm.players=malloc(nplayers*sizeof(player)); // shm.tablecards=malloc(nplayers*sizeof(card)); ftruncate(shmfd, sizeof(sharedmem));
error: shm = mmap(0,sizeof(sharedmem),prot_read|prot_write,map_shared,shmfd,0);
return 0; }
can tell me i'm doing wrong? thought attributes players , tablecards had allocated tried malloc no cigar.
Comments
Post a Comment