Mail Archives: djgpp/1997/01/10/23:40:29
Joe Wright wrote:
>
<<< Snip >>>>
> Good habits are as hard to break as bad ones. I always check the
> return from malloc (or fopen) in a conditional like:
>
> if ((ptr1 = (char *)malloc(1024)) == NULL)
> do_not_pass_go();
> ptr2 = ptr1;
>
> There is little you can do if malloc() fails and there is no use
> continuing with the program. Make it stop and try to fix it.
> In any case, if malloc() fails, neither ptr1 nor ptr2 contain valid
> pointers. And there is nothing to free() anyway.
I must agree with you (Joe) about good habits. But did you intend to
give the impression the program should terminate?
If malloc() fails on a modern multitasking operating system, there is
still the chance that giving the user the oportunity to close some files
or stop some other non-essential programs will free enough memory for
the program to continue without reloading/reinitializing.
Ah...while I'm here...could someone please tell me what djgpp is? I
assume this is some C/C++ compiler?
- Raw text -