Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify conditions under which to use volatile #7

Closed
sbseltzer opened this issue Aug 20, 2017 · 1 comment
Closed

Clarify conditions under which to use volatile #7

sbseltzer opened this issue Aug 20, 2017 · 1 comment

Comments

@sbseltzer
Copy link

sbseltzer commented Aug 20, 2017

In the README.md the rule:

If (a) you change local (stack) variables within your Try block, and (b) wish to make use of the updated values after an exception is thrown, those variables should be made volatile.

Is a little cryptic without an example for context. It seems to assume slightly more intimate knowledge of setjmp and longjmp.

More specifically, when you refer to stack variables, do you mean stack variables declared anywhere that make their way into a Try block. Does this include stack-allocated variables up the call tree?

Take for example:

void func(int *a)
{
  // ...
  int b = 0;
  Try {
    *a += 2;
    b = *a;
    Throw(MY_EX);
  } Catch(e) {
    // ...
  }
  printf("%d ?= %d", a, b);
}
void main()
{
  int x = 1;
  func(&x);
  printf("%d", x);
}

Are both a and b at risk here? Is x (the stack memory a points to) at risk?

@sbseltzer sbseltzer changed the title Clarify conditions under which to use volitile Clarify conditions under which to use volatile Aug 20, 2017
mvandervoord added a commit that referenced this issue Feb 13, 2020
Update docs to better describe potential stack issues (see issue #7)
@mvandervoord
Copy link
Member

Thanks for the suggestion and example. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants