Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does this compile in C but not C++ (sigaction)?
    primarykey
    data
    text
    <p>I get the following errors when trying to compile the below code using g++. When I compile it using gcc it works fine (other than a few warnings). Any help appreciated.</p> <pre><code>g++ ush7.cpp ush7.cpp: In function ‘int signalsetup(sigaction*, sigset_t*, void (*)(int))’: ush7.cpp:93: error: expected unqualified-id before ‘catch’ ush7.cpp:95: error: expected primary-expression before ‘catch’ ush7.cpp:95: error: expected `;' before ‘catch’ ush7.cpp:97: error: expected primary-expression before ‘catch’ ush7.cpp:97: error: expected `;' before ‘catch’ ush7.cpp:100: error: expected primary-expression before ‘catch’ ush7.cpp:100: error: expected `)' before ‘catch’ ush7.cpp:108: error: expected `)' before ‘;’ token ush7.cpp:108: error: expected `)' before ‘;’ token ush7.cpp: In function ‘int makeargv(const char*, const char*, char***)’: ush7.cpp:137: error: invalid conversion from ‘void*’ to ‘char*’ ush7.cpp:145: error: invalid conversion from ‘void*’ to ‘char**’ </code></pre> <hr> <pre><code>int signalsetup(struct sigaction *def, sigset_t *mask, void (*handler)(int)) { struct sigaction catch; catch.sa_handler = handler; /* Set up signal structures */ def-&gt;sa_handler = SIG_DFL; catch.sa_flags = 0; def-&gt;sa_flags = 0; if ((sigemptyset(&amp;(def-&gt;sa_mask)) == -1) || (sigemptyset(&amp;(catch.sa_mask)) == -1) || (sigaddset(&amp;(catch.sa_mask), SIGINT) == -1) || (sigaddset(&amp;(catch.sa_mask), SIGQUIT) == -1) || (sigaction(SIGINT, &amp;catch, NULL) == -1) || (sigaction(SIGQUIT, &amp;catch, NULL) == -1) || (sigemptyset(mask) == -1) || (sigaddset(mask, SIGINT) == -1) || (sigaddset(mask, SIGQUIT) == -1)) return -1; return 0; } </code></pre>
    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.
 

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