Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You probably don't want to use longjmp at all but I hate it when people answer a question with "Why would you want to do that?" As has been pointed out your <strong>longjmp()</strong> usage is wrong. Here is a simple example of how to use it correctly:</p> <pre><code>#include &lt;setjmp.h&gt; #include &lt;iostream&gt; using namespace std; jmp_buf jumpBuffer; // Declared globally but could also be in a class. void a(int count) { // . . . cout &lt;&lt; "In a(" &lt;&lt; count &lt;&lt; ") before jump" &lt;&lt; endl; // Calling longjmp() here is OK because it is above setjmp() on the call // stack. longjmp(jumpBuffer, count); // setjump() will return count // . . . } void b() { int count = 0; cout &lt;&lt; "Setting jump point" &lt;&lt; endl; if (setjmp(jumpBuffer) == 9) return; cout &lt;&lt; "After jump point" &lt;&lt; endl; a(count++); // This will loop 10 times. } int main(int argc, char *argv[]) { b(); // Note: You cannot call longjmp() here because it is below the setjmp() call // on the call stack. return 0; } </code></pre> <p>The problems with your usage of longjmp() are as follows:</p> <ol> <li>You don't call setjmp()</li> <li>You haven't allocated the jmp_buf either on the stack or dynamically. <strong>jmp_buf *bfj</strong> is just a pointer.</li> <li>You cannot cast a <strong>char *</strong> to <strong>jmp_buf *</strong> and expect it to work. C++ not a dynamic language it is statically compiled.</li> </ol> <p>But really, it is very unlikely that you should be using <strong>longjmp()</strong> at all.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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