Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #70972

Re: why "int s = setjmp(env)" fails?

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.c
Subject Re: why "int s = setjmp(env)" fails?
Date 2015-09-20 07:47 -0400
Organization A noiseless patient Spider
Message-ID <mtm688$rms$1@dont-email.me> (permalink)
References <d8e6c449-3aad-405e-b8a2-5fa73ee6a9a3@googlegroups.com>

Show all headers | View raw


On 9/20/2015 12:59 AM, i@introo.me wrote:
> while(setjmp(env)) will succeed,  (1)
>
> however,
>
> volatile int s = setjmp(env) will fail.  (2)
>
>
> what's the technical complexity/difficulty that hinders (2) ?

     "Nobody" has given you the Standard's language covering the
issue.  However, I imagine you were not asking about the existence
of the Standard's peculiar-seeming restrictions, but about the
reasons for them.  The same people who wrote the Standard and who
continue to amend it also maintain a companion document called the
Rationale, which tries to explain some of their thinking.  In the
matter of setjmp() and longjmp(), the Rationale says

	"One proposed requirement on setjmp is that it be usable like
	any other function [...]  Unfortunately, any implementation of
	setjmp as a conventional called function cannot know enough
	about the calling environment to save any temporary registers
	or dynamic stack locations used part way through an expression
	evaluation. [...]  The temporaries may be correct on the
	initial call to setjmp, but are not likely to be on any return
	initiated by a corresponding call to longjmp. These
	considerations dictated the constraint that setjmp be called
	only from within fairly simple expressions, ones not likely to
	need temporary storage.

	"An alternative proposal considered by the C89 Committee was to
	require that implementations recognize that calling setjmp is a
	special case, and hence that they take whatever precautions
	are necessary to restore the setjmp environment properly upon a
	longjmp call. This proposal was rejected on grounds of
	consistency: implementations are currently allowed to implement
	library functions specially, but no other situations require
	special treatment."

     If even this seems unconvincing to you, keep in mind that the
Standard is the product of many authors, who have (collectively) far
wider knowledge of "peculiar" platforms than any one person is likely
to possess.  Somebody in that group, perhaps several somebodies, told
the others about circumstances and machines where a seemingly simple
operation could be anything but, and the others listened to the tale.
See also, for example, the development of the <stdarg.h> facilities,
motivated by the fact that the older <varargs.h> API created problems
for some platforms.

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

why "int s = setjmp(env)" fails? i@introo.me - 2015-09-19 21:59 -0700
  Re: why "int s = setjmp(env)" fails? Nobody <nobody@nowhere.invalid> - 2015-09-20 10:53 +0100
  Re: why "int s = setjmp(env)" fails? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-09-20 07:47 -0400
    Re: why "int s = setjmp(env)" fails? supercat@casperkitty.com - 2015-09-21 08:51 -0700
      Re: why "int s = setjmp(env)" fails? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-09-21 12:52 -0400
        Re: why "int s = setjmp(env)" fails? supercat@casperkitty.com - 2015-09-21 11:44 -0700
          Re: why "int s = setjmp(env)" fails? Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-09-21 15:52 -0400
            Re: why "int s = setjmp(env)" fails? supercat@casperkitty.com - 2015-09-22 11:51 -0700
        Re: why "int s = setjmp(env)" fails? Tim Rentsch <txr@alumni.caltech.edu> - 2015-09-26 17:06 -0700
        Re: why "int s = setjmp(env)" fails? Paul N <gw7rib@aol.com> - 2015-09-28 14:28 -0700
  Re: why "int s = setjmp(env)" fails? Keith Thompson <kst-u@mib.org> - 2015-09-20 07:33 -0700
  Re: why "int s = setjmp(env)" fails? James Kuyper <jameskuyper@verizon.net> - 2015-09-20 11:11 -0400

csiph-web