Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's the meaning of this piece of code? void (*signal(int sig, void (*func)(int)))(int);
    primarykey
    data
    text
    <p>I came across this piece of code and completely got lost interpreting its meaning.</p> <pre><code>#include &lt;signal.h&gt; void (*signal(int sig, void (*func)(int)))(int); </code></pre> <p>What is a detailed explanation for the code at line 2?</p> <p>I know that <code>void</code> and <code>int</code> are types, the *func is a pointer for a function, and the brackets are for priority. But I still don't get the (*signal ...), the (int), and the whole thing combined together. The more detailed, the better.</p> <p>Probably I've known the meaning/effect of this declaration. But I had to make some more trials to help me understand what's going on, as below:</p> <pre><code> 1 #include &lt;signal.h&gt; 2 void (*signal)(int sig, void (*func)(int)); 3 void (*signal)(int); // then void (signal)(int) again. 4 //void (*signal(int sig, void (*func)(int)))(int); //break this line into two lines above 5 6 int main(){} </code></pre> <p>In the above code, I broke <code>void (*signal(int sig, void (*func)(int)))(int)</code> into two lines. For line 3, I tried both <code>void (*signal)(int)</code> and <code>void (signal)(int)</code>, with the same error result that indicated that I was trying to redeclare <code>signal</code>:</p> <blockquote> <p>TestDeclaration.c:2: error: 'signal' redeclared as different kind of symbol /usr/include/signal.h:93: error: previous declaration of 'signal' was here<br> TestDeclaration.c:3: error: 'signal' redeclared as different kind of symbol /usr/include/signal.h:93: error: previous declaration of 'signal' was here</p> </blockquote> <p>Now I know both the trials are incorrect ways of declaration, but why are they incorrect? Why is the original way of declaration NOT a redeclaration?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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