Error Return (was Re: (char *)(-1))

Mike I'll think of something yet Meyer mwm at eris.berkeley.edu
Sat Aug 5 14:46:49 AEST 1989


In article <594 at cybaswan.UUCP> iiitsh at cybaswan.UUCP (Steve Hosgood) writes:
<I guess that an extension of the form:
<
<	if (errval(foo = bar())) {
<		<error code goes here>
<		<could use 'foo' to get more details of the error>
<	}
<
<..would be most acceptable. 'errval' could be made a reserved word on new
<systems (tests the carry bit), and implemented as a macro on older ones for
<backward compatability:
<
<# define	errval(x)	(x) < 0
<
<..or
<
<# define	errval(x)	(x) == -1
<
<..or something like that, though some sort of cast will be reqd of course.

How about:

#define errval(x)	(errno = 0, (x), errno)

It'll even work on the current standard. Whether you can get this to
turn into tweaks to the carry flag (I hope that nobody would advocate
referring to hardware flags in the standard; there's already hardware
that C runs on without such flags) in a standard-conforming compiler
is an interesting question.

	<mike
--
Can't buy happiness no matter what you do		Mike Meyer
Can't get to heaven on roller skates			mwm at berkeley.edu
Can't take a taxicab to Timbuktu			ucbvax!mwm
Life is hard.						mwm at ucbjade.BITNET



More information about the Comp.std.c mailing list