Re: malloc()/realloc() - have I got this right?
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Fri, 30 May 2008 17:53:18 -0400
santosh wrote:
Keith Thompson wrote:
Richard Heathfield <rjh@xxxxxxxxxxxxxxx> writes:
CBFalconer said:
Richard Heathfield wrote:
CBFalconer said:... snip ...
enum {OK = 0, NOMEM};
Are those the only two failure conditions? What about end of file?
Or a stream error? Why not make it possible to report those?
You didn't read the whole routine. It also returns EOF, which is
not defined here. I did point out that this listing omitted the
documentation etc.
Your point is well-taken, although it does seem that you fail to
distinguish between genuine end-of-file and a stream error.
So does fgets(). That's what feof() and ferror() are for.
[snip]
Nothing can be done about fgets but a new function /could/
disambiguate between these two conditions thus freeing the caller
from some more repetitive work.
Ridiculous. Most use of the function simply runs until a non-zero
is returned, after which the operation ends. It may be because of
EOF, or because of error. In either case, no further input is
available. If there is a need to distinguish EOF from errors, it
can be done at that point.
This is not a matter of correctness, but of design philosophy.
--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
.
- Follow-Ups:
- Re: malloc()/realloc() - have I got this right?
- From: santosh
- Re: malloc()/realloc() - have I got this right?
- From: Antoninus Twink
- Re: malloc()/realloc() - have I got this right?
- References:
- malloc()/realloc() - have I got this right?
- From: Dave
- Re: malloc()/realloc() - have I got this right?
- From: CBFalconer
- Re: malloc()/realloc() - have I got this right?
- From: Richard Heathfield
- Re: malloc()/realloc() - have I got this right?
- From: CBFalconer
- Re: malloc()/realloc() - have I got this right?
- From: Richard Heathfield
- Re: malloc()/realloc() - have I got this right?
- From: CBFalconer
- Re: malloc()/realloc() - have I got this right?
- From: Richard Heathfield
- Re: malloc()/realloc() - have I got this right?
- From: Keith Thompson
- Re: malloc()/realloc() - have I got this right?
- From: santosh
- malloc()/realloc() - have I got this right?
- Prev by Date: Re: Determine the size of malloc
- Next by Date: Re: Help with atoi function for a numero program.
- Previous by thread: Re: malloc()/realloc() - have I got this right?
- Next by thread: Re: malloc()/realloc() - have I got this right?
- Index(es):
Relevant Pages
|