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


Groups > comp.lang.c > #70977

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

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: why "int s = setjmp(env)" fails?
Date 2015-09-20 11:11 -0400
Organization Self
Message-ID <55FECC86.9@verizon.net> (permalink)
References <d8e6c449-3aad-405e-b8a2-5fa73ee6a9a3@googlegroups.com>

Show all headers | View raw


On 09/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) ?
> 
> AFAIK, (2) is still a simple statment.

"Nobody" has already cited for you the relevant rules, and Eric Sosman
have given you the general context of why those rules were written that
way. But neither has explained specifically what the problem is. If you
look at the rules "Nobody" cited, you notice a common thread: every
place where setjmp() calls don't have undefined behavior falls into one
of two categories: the return value from setjmp is either completely
ignored, or is used immediately to determine how the code will branch,
without being stored anywhere, not even as a temporary in a more
complicated expression. It would appear to be the case that it's the
storage of the return value that the committee considered to be
problematic. Why? I don't know, I'm not an implementor, and the reason
isn't obvious to me - but that does seem to be the relevant issue.

If you want to know which value setjmp() returned, make it the
controlling expression of a switch() statement, and provide case:
statements for each value you're interested in distinguishing from the
default: case.

Back to comp.lang.c | Previous | Next — Previous 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