Re: Return type of "readin" and correct error handling
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Sun, 17 Jun 2007 12:51:57 +0000
Victor Lagerkvist said:
<snip>
char *readin();
However, in case anything goes wrong readin should be able to return
an error code to the function that called it.
I "solved" the problem with the following declaration of readin:
int readin (char *);
Which makes it possible to return -1, and the function that calls
readin always tests the return value in an if-clause.
How does readin() know how much data it can safely store in the buffer
whose first byte is pointed to by its parameter?
From my brief
and incomprehensible explanation, does this look like an acceptable
solution - or are there better, standardized ways to perform error
testing? I'm new to C and am therefore trying to pick up as few bad
habits as possible.
My own strategy is much like yours - I generally return an int error
code from my functions, unless they are object-creating functions, in
which case I return either a pointer to the new object or NULL if the
object could not be created.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
.
- Follow-Ups:
- Re: Return type of "readin" and correct error handling
- From: Victor Lagerkvist
- Re: Return type of "readin" and correct error handling
- References:
- Return type of "readin" and correct error handling
- From: Victor Lagerkvist
- Return type of "readin" and correct error handling
- Prev by Date: Re: Pointer Ambiguity
- Next by Date: Re: factorial and exponent
- Previous by thread: Re: Return type of "readin" and correct error handling
- Next by thread: Re: Return type of "readin" and correct error handling
- Index(es):
Relevant Pages
|