Path: utzoo!mnetor!uunet!husc6!purdue!umd5!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Volatile is Necessary Message-ID: <10864@mimsy.UUCP> Date: 31 Mar 88 01:57:17 GMT References: <8107@sol.ARPA> <77200028@uiucdcsp> <1259@PT.CS.CMU.EDU> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 40 In article <1259@PT.CS.CMU.EDU> jgm@K.GP.CS.CMU.EDU (John Myers) writes: >Is R. Stallman's reading of the ANSI draft wrong, or isn't it >necessary to declare automatic variables as 'volatile' in order to >guarantee that their values will be preseved across a setjmp/longjmp? [\S => section symbol; |word| => C-style text) p. 119, \S 4.6.2.1, The |longjmp| function All accessible objects have values as of the time |longjmp| was called, except that the values of objects of automatic storage duration that do not have |volatile| type and have been changed between the |setjmp| invocation and |longjmp| call are indeterminate. As it bypasses the usual function call and return mechanisms, ... However, if the |longjmp| function is invoked from a nested signal handler (that is, from a function invoked as the result of a signal raised during the handling of another signal), the behavior is undefined. [This answers another recent question.] On p. 118 (\S 4.6.1.1, The |setjmp| macro), however, we see that The |setjmp| macro shall be implemented as a macro, not as an actual function. If the macro definition is suppressed in order to access an actual function, the behavior is undefined. No reason is given here for this requirement (which, incidentally, makes it technically illegal NOT to |#define setjmp| as something, even if it is just as |_setjmp|), but it would make sense if it were intended as a constraint on the *programmer* so that || could say, e.g., #define setjmp(env) _builtin_setjmp(env) which would allow the compiler to implement this as a builtin, and thus to `fix' all local automatic variables, so that the constraint in \S 4.6.2.1 need not apply. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris