Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Safety of casting from 'long' to 'int'
Date: Tue, 12 May 2026 22:31:12 -0700
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <86lddnlvtr.fsf@linuxsc.com>
References: <10su8cn$am9i$1@dont-email.me> <10tdu47$pms4$3@kst.eternal-september.org> <10tgqgk$rpk$1@reader1.panix.com> <10thb36$1prnt$1@kst.eternal-september.org> <10tlc73$qq2$1@reader1.panix.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Wed, 13 May 2026 05:31:13 +0000 (UTC)
Injection-Info: dont-email.me; logging-data="2596065"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19WlJAqSMy1z5/WGxw0aY3mwSiiAL4r6xw="; posting-host="ace8b6eaa328dcf44f89a3207699c4cb"
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:n1vhOUESM+4gpS0zfjabkoeJ3Ys= sha1:L3KpkpXVf1dI/XfKoJyZ/rW/MEg= sha256:Z7HNcxpesyRg9/B1jXixSPeMHAZWW/Ow7Xa4kWLfj70= sha1:sZLzxo6glMjMk5spZZd5KCoB0b8=
Xref: csiph.com comp.lang.c:398843
cross@spitfire.i.gajendra.net (Dan Cross) writes:
[...]
> It is not clear to me that `longjmp` out of a non-nested signal
> handler is still well-defined as of C11, though it is explicitly
> stated to be C89.
It seems you are misunderstanding what the standards are saying.
The description of longjmp() says (paraphrasing) that it restores
the environment where the relevant setjmp() was done. There is
in C89 a passage about returning from signal handlers and so
forth, but that is followed by a carveout for nested signal
handlers, which in C89 is undefined behavior. (I assume that
also holds for C90 but I haven't verified that.)
Starting in C99, any mention of interrupts and signal handlers was
removed, along with the carveout. Because there is a definition
for what longjmp() does, the behavior is defined, and there is no
undefined behavior (not counting things like doing a longjmp()
with a jmp_buf that wasn't set up, etc). Removing the mention of
interrupts and signals, and also removing the carveout, only makes
longjmp() more defined, not less.