More thoughts on "Error Return"

david Fridley david at psitech.UUCP
Sat Aug 12 06:47:03 AEST 1989


I have a new idea, or at least half of one:

	func(..)
	{	:
		:
		if(err)
			return("func: there has been an error\n");
		else
			return(cptr);
	}

	main()
	{	tmp=func(..);
		if(tmp>_CODESEGMENTSTART && tmp <=CODESEGMENTEND)
		{	/* there has been an error */
		}
	}

Advantages: you do not need a global list of error code to figure out what
the error is.  New functions and libraries can implement their own errors
with out fear of confusing meaning with those of other functions/libraries.
The pointers will be valid, yet it will be possible to determine that they
are errors.. It may even be possible to put error messages
in their own seperate sections.

Disadvantages: Some compilers may put strings in the data segment, or not
even have segments?  Some functions may correctly return static strings
or pointers to functions. For these functions we won't be able to use this
method of error handeling.

The basic idea here is to let each module define it's own errors, to avoid
global variables (like errno), and to return an otherwise valid pointer
that can be determined to be an error with out specific knolege of the
errors returned by that function.

Standard changes: (The chicken and the egg story).

The reason that we have a C standard is so that we can write code that is 
portable between C compilers.  I can not write code that takes advantage
of one Company's extensions because it will not run on the other compilers
I use (The above Idea will work on all the compilers I use now, but remember
it is only half an Idea.).  Perhaps after ANSI is finally final (I had to
say it (why aren't nested ()'s allowed in English. Where is the English
standard committe so I can complain.)) they will be able to consider
additions of their own, because this will become the only way to make
changes to the language. Perhaps the partisipation of some number of complier
companys will be required in order to demonstrate it's fiesability, usefullness,
and desirability.

If we are going to make additions to C I propose that we make them as general
as possible (like returning multiple values from a function), rather than
specific (like returning one more value, or an error flag).
	(ret1,ret2...)=func(p1,p2...)
	{ret1,ret2,..}=func(p1,p2...)
The first one looks better to me than the second, but I am concerned about
function, not syntax.


-- 
david.
DISCLAIMER: If it's important have a backup.  If it ain't broke don't fix it.
Proceed at your own risk.  My oponions are MY own.  Spelling does not count.
My fondest dream is to leave this planet.



More information about the Comp.std.c mailing list