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


Groups > comp.lang.c > #71033

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-21 15:52 -0400
Organization A noiseless patient Spider
Message-ID <mtpn33$nb7$1@dont-email.me> (permalink)
References <d8e6c449-3aad-405e-b8a2-5fa73ee6a9a3@googlegroups.com> <mtm688$rms$1@dont-email.me> <f82143ca-2f45-4ea4-bc78-dc43962cab8b@googlegroups.com> <mtpch6$a2s$1@dont-email.me> <fb16b8a6-ef68-4214-b2ae-78a401efb339@googlegroups.com>

Show all headers | View raw


On 9/21/2015 2:44 PM, supercat@casperkitty.com wrote:
> On Monday, September 21, 2015 at 11:52:57 AM UTC-5, Eric Sosman wrote:
>> 	"No" -- The authors of the Standard were a bunch of imbeciles,
>> 	not one of whom knew anything about C, compilers, or computers.
>
> Or else the authors made their decision at a time when there would have
> been no difficulty with simply using a global variable for the purpose (and
> thus not much benefit to allowing the indicated usage), and have
> not re-evaluated that decision in the light of things like threading which
> have become much more relevant in years since.

     Thread-local storage exists for a reason.

> Given that compilers are required to handle "setjmp" as a switch() operand,
> I find it hard to imagine an implementation where an assignment to an
> automatic volatile variable would be problematic.

     Okay: You find it hard to imagine.  Apparently, the Committee's
imagination roamed more widely than yours.

>>       Where is it written that the value returned by setjmp() is the
>> one and only value available to the code?
>
>> Observe that `result' could, if desired, be of any (complete) type
>> at all: int, double, struct foobar, ...
>
> That style requires either that all functions between the "setjmp" and the
> "longjmp" pass the necessary address.  Using a static or thread-static
> variable may sometimes be more practical in cases where the jmp_buff itself
> is such a variable, but may itself be somewhat icky.

     Observe that the `jmp_buf' must also be communicated from the
setjmp() caller to the longjmp() caller, so passing a result slot
incurs no ickiness beyond whatever is already present.  Put both
the `jmp_buf' and the result in a single struct, if you like.

>>       The fact that a preordained signalling channel is available does
>> not mean you cannot also use other and less restrictive channels.
>
> I guess I'm curious as to the intended usage of the longjmp() parameter.  I
> guess in the scenario where one wants to distinguish two kinds of longjmp()
> actions, one could pass values of 1 and 2, use an automatic volatile
> variable to distinguish the first and second returns from setjmp(), and
> thus compare the return value of "longjmp" against 1 (and in the case where
> it isn't 1, use the other automatic variable to distinguish cases where it
> would have returned zero) but it seems rather more awkward than just being
> able to store the return to a local variable.

     Sure, it's more awkward.  It's a weird-on-the-face-of-it set of
restrictions.  But then, setjmp() itself is pretty weird, too.

-- 
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