home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / unix / internal / 2108 < prev    next >
Encoding:
Text File  |  1993-01-11  |  1.3 KB  |  46 lines

  1. Newsgroups: comp.unix.internals
  2. Path: sparky!uunet!mcsun!sun4nl!xelion!hans
  3. From: hans@xelion.nl (Hans Bos)
  4. Subject: Re: Question about longjmp () 
  5. Message-ID: <C0os9v.CG@xelion.nl>
  6. Organization: Xelion bv
  7. References: <C0JpMo.1rGr@austin.ibm.com> <1993Jan9.124323.13018@csie.nctu.edu.tw>
  8. Date: Mon, 11 Jan 1993 11:08:19 GMT
  9. Lines: 35
  10.  
  11. cp78065@csie.nctu.edu.tw (Ji-Tzay Yang) writes:
  12.  
  13. >Sivarama Subramanian (subra@bynar.austin.ibm.com) wrote:
  14. >: Hi folks,
  15. >:     I have the following code segment.
  16. >:     main ()
  17. >:     {
  18. >:         int i = 0;
  19. >:         jmp_buf buf;
  20. >:         setjmp (buf);
  21. >:         printf ("%d\n", i);
  22. >:         if ( i == 1 )
  23. >:             exit;
  24. >:         i = 1;
  25. >:         longjmp (buf, 1);
  26. >:     }
  27. >:     My question is, should the value of i change or not.
  28.  
  29. >  After running the program, the value 'i' is changed, and it should be
  30. >  changed.
  31.  
  32. >  But is there any consideration for 'i' to keep its orignal value?
  33.  
  34. I believe that in ANSI C nothing is guaranteed for local variables 
  35. after a longjmp, unless they are declared volatile.
  36.  
  37. So if you use 'volatile int i = 0;', the value of i should be 1 after
  38. the longjmp.
  39.  
  40.  
  41. -- 
  42. Hans Bos                            domain : hans@xelion.nl
  43. Xelion BV                          uucp   : ...!sun4nl!xelion!hans
  44. Postbus 88                         phone  : +31 15 622121
  45. 2600 AB Delft, The Netherlands     fax    : +31 15 621760
  46.