Must setjmp() be a macro?

Fred Zlotnick fred at mindcraft.com
Sat Mar 16 07:25:38 AEST 1991


I'm having trouble understanding what the C standard requires of setjmp().
Section 4.6 starts out with

	The header <setjmp.h> defines the macro setjmp and declares
	one function [longjmp] and one type [jmp_buf] ...

This would seem to imply that setjmp() must be implemented as a macro on a
conforming implementation.  However, later in the same section, it states

	It is unspecified whether setjmp is a macro or an identifier
	with external linkage.

This seems to imply the opposite: that the implementor has a choice.  The
rationale doesn't help much.  So what is the consensus of the newsgroup,
and of the C standard experts therein?

One system in our lab that claims ANSI C conformance has a <setjmp.h> that
includes lines like these:

	#if __STDC__ == 1
	extern int setjmp(jmp_buf env);
	#define setjmp(X)       setjmp(X)
	#endif

Another system in our lab, also claiming ANSI conformance, has the prototype
but not the macro.  Clearly I'm not the only one who's confused.

Note that, as Chuck Karish has pointed out to me, this has implications for
POSIX.1.  In that standard it states (8.3.1.2) that

	The sigsetjmp() macro shall comply with the definition of the
	setjmp() macro in the C Standard.
----
Fred Zlotnick                       |	#include <std.disclaimer>
fred at mindcraft.com                  |	#include <brilliant.quote>
...!{decwrl,ames,hpda}!mindcrf!fred |



More information about the Comp.std.c mailing list