Incompatible types when assigning to type 'struct compartido'

Posted by user1660559 on Stack Overflow See other posts from Stack Overflow or by user1660559
Published on 2012-09-10T15:32:25Z Indexed on 2012/09/10 15:38 UTC
Read the original article Hit count: 255

Filed under:
|
|

I have one problem with this code. I should create one structure and share it across 5 new process created from the father:

#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <time.h>

struct compartido {
    int pid1, pid2, pid3, pid4, pid5;   
    int propietario;            
    int contador;                   
    int pidpadre;
};

struct compartido var;  


int main(int argc, char *argv[]) {

    key_t llave1,llavesem;
    int idmem,idsem;    
    llave1=ftok("/tmp",'a');

    idmem=shmget(llave1,sizeof(int),IPC_CREAT|0600);
    if (idmem==-1) {
       perror ("shmget");
       return 1;
    }

var=shmat(idmem,0,0); /*This line is giving the error*/

/*rest of the code*/
}

The exact error is giving is: error: incompatible types when assigning to type 'struct compartido' from type 'void *'

I need to put this structure in the shared variable to be able to see and modify all those data from the 6 process (5 children and the father).

What I'm doing bad? Thanks in advance and best regards,

© Stack Overflow or respective owner

Related posts about c

    Related posts about pointers