title: Passing a struct to a process through shared memory in C
body: <p>For a uni assignment I am trying to create a structure in shared memory, write some data in it, and then let the child read it. I've come up with something but, since I am new to C, I am getting some errors that I can't quite understand, here is the code:</p>
  
  <pre><code>typedef struct file
  {
      int pid;
      char tipo[2];
      char nome[20];
      unsigned long genoma;
      char shmPtr[];
  } file_entry;
  
  int main (void)
  {
  
  int shmid;
  int n;
  file_entry *entries;
  
  if (fork() == 0) {
      if ((shmid = shmget(20441, sizeof(file_entry) + 256, IPC_CREAT | 0666)) == -1) {
          printf("shmget");
          exit(2);
      }
  
      entries = (file_entry*) shmat(shmid, 0, 0);
      if (entries-&gt;shmPtr == (char *) -1) {
          printf("problem2");
          exit(2);
      }
  
      printf("\nChild Reading ....\n\n");
      printf("%c\n", entries-&gt;shmPtr[0]);
      printf("%c\n", entries-&gt;shmPtr[1]);
      printf("%c\n", entries-&gt;shmPtr[2]);
      printf("%c\n", entries-&gt;shmPtr[3]);
      putchar('\n');
      printf("\nDone\n\n");
  } else {
      if ((shmid = shmget(20441, sizeof(file_entry) + 256, IPC_CREAT | 0666)) == -1) {
          printf("problem3");
          exit(2);
      }
  
      entries = (file_entry *) shmat(shmid, 0, 0);
      if (entries-&gt;shmPtr == (char *) -1) {
          printf("problem4");
          exit(2);
      }
      printf("done attachment");
  
      int pidD = 1234;
      char tipoD[2] = "A";
      char nomeD[20] = "NOMEINDIVIDUO";
      unsigned long genomaD = 10000;
  
  
      entries-&gt;shmPtr[0]= pidD;
      entries-&gt;shmPtr[1]=tipoD;
      entries-&gt;shmPtr[2]=nomeD;
      entries-&gt;shmPtr[3]= genomaD;
  
  
      wait(NULL);
      shmdt(&amp;shmid);
  }
  exit(0);
  </code></pre>
  
  <p>}</p>
  
  <p>The errors I'm getting are those: </p>
  
  <pre><code>shared memory example 2.c:74:27: warning: incompatible pointer to integer conversion assigning to 'char' from 'char [2]' [-Wint-conversion]
      entries-&gt;shmPtr[1]=tipoD;
                        ^~~~~~
  shared memory example 2.c:75:27: warning: incompatible pointer to integer conversion assigning to 'char' from 'char [20]' [-Wint-conversion]
      entries-&gt;shmPtr[2]=nomeD;
  </code></pre>
  
  <p>I tried to declare the dimension of the variables in the struct and the variables on the father to be the same thinking that it would help, but it didn't. Does anyone know how to solve this? If you also have some example code that would be appreciated.</p>