Why leave the error handling to the caller?
- From: Chad <cdalten@xxxxxxxxx>
- Date: Sun, 17 Jun 2007 09:06:39 -0700
On to top of page 163 in the book "The C Programming Langauge" by K &
R, they have the following:
char *strdup(char *s)
{
char *p;
p=(char *)malloc(strlen(s)+1);
if( p != NULL)
strcpy(p,s):
return p;
}
They then go on to say
"strdup passes that value on, leaving error-handling to its caller"
Why leave the error-handling to it's caller? Couldn't a person go like
char *strdup(char *s)
{
char *p;
if (p=(char *)malloc(strlen(s)+1) == NULL)
exit(1);
else
strcpy(p,s):
return p;
}
Chad
.
- Follow-Ups:
- Re: Why leave the error handling to the caller?
- From: pete
- Re: Why leave the error handling to the caller?
- From: Johan Bengtsson
- Re: Why leave the error handling to the caller?
- From: Coos Haak
- Re: Why leave the error handling to the caller?
- From: Gordon Burditt
- Re: Why leave the error handling to the caller?
- From: Malcolm McLean
- Re: Why leave the error handling to the caller?
- From: Richard Heathfield
- Re: Why leave the error handling to the caller?
- From: jacob navia
- Re: Why leave the error handling to the caller?
- Prev by Date: GCC C Compiler Installation
- Next by Date: All programs in an interface
- Previous by thread: GCC C Compiler Installation
- Next by thread: Re: Why leave the error handling to the caller?
- Index(es):
Relevant Pages
|
|