Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 362051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:12:29+00:00 2026-05-12T13:12:29+00:00

My questions aims at the behaviour of setjmp/longjmp concerning local variables. Example code: jmp_buf

  • 0

My questions aims at the behaviour of setjmp/longjmp concerning local variables.

Example code:

jmp_buf env;


void abc()
{
  int error;

  ... 
  if(error)
    longjmp(env);
}


void xyz() {
  int v1;           // non-volatile; changed between setjmp and longjmp
  int v2;           // non-volatile; not changed between setjmp and longjmp
  volatile int v3;  // volatile;     changed between setjmp and longjmp
  volatile int v4;  // volatile;     not changed between setjmp and longjmp 

  ...

  if(setjmp(env)) {
    // error handling
    ...
    return;
  }

  v1++; // change v1
  v3++; // change v3

  abc();
}


int main(...) {
  xyz();
}

The documentation of setjmp/longjmp says:

“All accessible objects have values as of the time longjmp() was called,
except that the values of objects of automatic storage duration which
are local to the function containing the invocation of the corresponding
setjmp() which do not have volatile-qualified type and which are changed
between the setjmp() invocation and longjmp() call are indeterminate.”

I see following two possible interpretations:

intepretation1:

Local variables are restored, except those that are both

  • non-volatile and
  • changed

intepretation2:

Local variables are restored, except

  • those that are non-volatile and
  • those that are changed

According to interpretation1 after longjmp only v1 is undefined. v2, v3, v4 are defined.
According to interpretation2 after longjmp only v4 is defined. v1, v2, v3 are undefined.

Which one is right?

BTW: I need a general (“portable”) answer that is valid for all compilers, i.e. trying out with one particular compiler doesn’t help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T13:12:29+00:00Added an answer on May 12, 2026 at 1:12 pm

    Interpretation 1 is correct. If the Interpretation 2 was intended, the original text would have used “or which are changed” instead of “and”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The questions says everything, take this example code: <ul id=css-id> <li> <something:CustomControl ID=SomeThingElse runat=server
Questions #1 through #4 on the Joel Test in my opinion are all about
Questions : What does the kernel do if you stick a shell-script into the
Several questions about functional programming languages have got me thinking about whether XSLT is
My questions is simple! Would you start learning Smalltalk if you had the time?
Two questions: Can someone point me to unbiased data that compares .NET performance to
Similar questions have been asked, but nothing exactly like mine, so here goes. We
Two Questions: Will I get different sequences of numbers for every seed I put
Similar questions to this one have been asked but none seem to address my
I saw many questions asking 'how' to unit test in a specific language, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.