🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3997

Re: EXIT_FAILURE problem

#3997
From: Mike Schilling
Date: Thu, 14 Sep 1995 19:06
59 lines
2599 bytes
Jeremy Fitzhardinge (jeremy@sw.oz.au) wrote:
: In <1995Sep11.221423.6651@forte.com> mikes@forte.com (Mike Schilling) writes:
: >Why couldn't the standard define another function called, say 
: >
: >	void sys_exit(OS_RET_TYPE)
: >
: >which does what exit does in terms of cleanup, and then exits with 
: >OS-specific exit status.  The standard couldn't specify the actual type
: >of OS_RET_TYPE, of course, or how to map OS-specific exit statuses into
: >C types.  Much of the usefulness of sys_exit *would* be a quality of 
: >implementation issue.  Still, writing largely portable programs which 
: >use OS-specific features where possible and appropriate would be far eaiser
: >if this kind of thing were encouraged and where possible mandated.
: 
: This is getting pretty silly.  Why have the standard define something
: completely undefined?  It would be impossible for a conforming program
: to use such a sys_exit() without knowing what OS_RET_TYPE is, which
: means it can't be used unless a specific OS is targeted, which means it
: would be non-portable.  There's no point in having the standard define
: a feature which can't be used portably.
: 
: The standard defines two states a program can terminate with:  success
: and failure.  If you want to communicate a non-standard state to the
: environment, you have to use a non-standard interface, and have it
: become a non-conforming program.  By definition, the standard doesn't,
: and shouldn't, cover non-standard interfaces.

Or if you'd prefer, I don't mind the following:

	typedef int exit2_func(void *arg);
	void exit2(exit2_func *func, void *arg);

	exit2 does all of the cleanup work done by exit, and calls 
	func with argument arg immediately before actually exiting.  
	On func's return, exit exits with the func's
	return value.  (In the interesting cases, of course, 
	func won't return.)

The point remains to portably separate the non-portable part of exit's
work (returning status to the OS) from the portable part (everything
else.)

I can now write, once and for all:

#ifdef UNIX
int exitFunc(void *status)
{
	return *(int *)status;
}
#endif

#ifdef VMS
int exitFunc(void *status)
{	
	sys$exit(*(int *)status);
}
#endif

Mike
Technical Details
Message-ID: <1995Sep14.190646.11346@forte.com>
Path: arc1-ca.pugleaf.net!uucp3.netcom.com!forte!mikes
References: <jeremy.810996048@suede.sw.oz.au>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!uucp3.netcom.com!forte!mikes
From: mikes@forte.com (Mike Schilling)
Subject: Re: EXIT_FAILURE problem
Message-ID: <1995Sep14.190646.11346@forte.com>
Organization: Forte Software Inc.
X-Newsreader: Tin 1.1 PL5
References: <jeremy.810996048@suede.sw.oz.au>
Date: Thu, 14 Sep 1995 19:06:46 GMT