Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can I attach values to struct sembuf that is in a struct converted to a pointer?
    primarykey
    data
    text
    <p>I need to pass some data to shared memory, that will only accept pointers. So I need the semaphore to be in this structure, but if it is I cant add values to it. how can I fix it? so, this is the structure:</p> <pre><code>typedef struct querem_usar { int conta_homem; int conta_mulher; int conta_crianca; struct sembuf lock[4]; struct sembuf unlock[4]; } queremUsar; </code></pre> <p>and this is how I have to declare it:</p> <pre><code>queremUsar *banheiro; </code></pre> <p>But if I try to set a value to lock or unlock, like this:</p> <pre><code>banheiro-&gt;lock[0].sem_num = 0; banheiro-&gt;lock[0].sem_op = -1; banheiro-&gt;lock[0].sem_flg = 0; banheiro-&gt;unlock[0].sem_num = 0; banheiro-&gt;unlock[0].sem_op = 1; banheiro-&gt;unlock[0].sem_flg = 0; </code></pre> <p>I get segmentation fault. I already tried to use malloc, like this:</p> <pre><code>banheiro-&gt;lock = (struct sembuf*)malloc(sizeof(struct sembuf)); banheiro-&gt;unlock = (struct sembuf*)malloc(sizeof(struct sembuf)); </code></pre> <p>but it gave me the error: </p> <pre><code>error: incompatible types when assigning to type ‘struct sembuf[4]’ from type ‘struct sembuf *’ </code></pre> <p>Please, help me fix it? The entire code is here: <a href="https://gist.github.com/4553796" rel="nofollow">https://gist.github.com/4553796</a> the line 71 shouldn't be commented, i did this to test the code. Go ahead and try it, it's for university so it's not complicated at all, it should be the unisex bathroom problem using shared memory (shm, I cant use threads) and semop() as the semaphores.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload