www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/06/23/03:28:47

Date: Tue, 23 Jun 1998 10:28:28 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Morten Welinder <terra AT diku DOT dk>
cc: djgpp-workers AT delorie DOT com
Subject: Re: setjmp
In-Reply-To: <199806230336.FAA23970@tyr.diku.dk>
Message-ID: <Pine.SUN.3.91.980623102807.14765L-100000@is>
MIME-Version: 1.0

On Tue, 23 Jun 1998, Morten Welinder wrote:

> If I recall correctly, setjmp should be a macro, not a library function.

It amazes me time and again how many subtle points can the ANSI C
Standard have, even for somebody who uses the language for a long
time...

Here's what ANSI C says about this:

  7.6 Nonlocal jumps <setjmp.h>
  ....
  It is unspecified whether `setjmp' is a macro or an identifier
  declared with external linkage.  If a macro definition is suppressed
  in order to access an actual function, or if a program defines an
  external identifier with the name `setjmp', the behavior is
  undefined.

The Standard then goes on referencing `setjmp' as ``the setjmp macro''
throughout the rest of the text ;-).

P.J. Plauger's ``The Standard C Library'' explains that defining a
function `setjmp' and a macro with that same name is a way to ensure
that no program declares `setjmp' if it includes <setjmp.h>, and no
program defines its own function `setjmp', even if it doesn't include
<setjmp.h>.

So it seems that either macro or function is okay, and if we want to
accept Plauger's suggestion, then adding something like the following
to <setjmp.h> should be enough:

  #define setjmp(foo)  setjmp(foo)

I suggest to add this line.  Comments?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019