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

  • SEARCH
  • Home
  • 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 6472045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:17:46+00:00 2026-05-25T06:17:46+00:00

Advanced Programming in the UNIX Environment by W. Richard Stevens states: What are the

  • 0

Advanced Programming in the UNIX Environment by W. Richard Stevens states:

“What are the the states of the automatic variables and register
variables in the main function?”

with regard to what happens when you longjmp back to main (or another function) from somewhere lower down the stack.

It goes on to say:

“It depends. Most implementations do not try to roll back these
automatic variables and register variables, but all that the standards
say is that their values are indeterminate. If you have an automatic
variable that you don’t want rolled back, define it with the
volatile attribute. Variables that are declared global or static
are left alone when longjmp is executed.

It seems like he’s saying that normal stack-variables will not have their values set back to what they were at the time of the setjmp – but then the rest of the function couldn’t rely on its stack variables after the longjmp back to it which seems crazy, so I’m guessing I’m wrong.

Can someone define “automatic variables” for me and explain what specifically isn’t set back to its original value and why that is?

  • 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-25T06:17:46+00:00Added an answer on May 25, 2026 at 6:17 am

    All it’s saying is that if

    1. you have an automatic (function-local non-static) variable that’s not declared volatile; and
    2. you change the value of the variable between setjmp and longjmp

    then after the longjmp the value of that variable becomes indeterminate.

    I believe this has to do with the possibility of such variables residing in CPU registers rather than in RAM, and the associated difficulty of preserving the values of such variable across the longjmp.

    Here is a quote from the gcc manual:

    If you use longjmp, beware of automatic variables. ISO C says that
    automatic variables that are not declared volatile have undefined
    values after a longjmp. And this is all GCC promises to do, because
    it is very difficult to restore register variables correctly, and one
    of GCC’s features is that it can put variables in registers without
    your asking it to.

    If the potential loss of variable values is a problem in your use case, declare the relevant variables as volatile.

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

Sidebar

Related Questions

I am reading APUE (Stevens' Advanced Programming in the UNIX Environment ), so there
I'm currently reading Advanced Programming in the Unix Environment by Stevens/Rago. Within the process
When reading about pipes in Advanced Programming in the UNIX Environment, I noticed that
I am learning APUE.2e (Advanced Programming in the UNIX® Environment, Second Edition) these days
In the Advanced Programming in the Unix Environment book there's a part (ch 8.14,
I'm reading a book (Advanced Programming in the UNIX Environment) and I'm going through
a strange idea comes to me when I'm reading APUE(Advanced Programming in UNIX Environment).
i have a unix c programming assignment in which i do some advanced C
I was trying this program from Advance Programming in Unix Environment. #include<stdio.h> #include<signal.h> static
In the example from, Advance Programming in the Unix Environment the following sample program

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.