07-03-04 02:24 AM
Stefan Monnier wrote:
>
>
>
>
> Interesting. I never noticed that it disallows it. Do you remember which
> part of the standard disallows it?
This has been a topic of recurring debate in the C groups,
because the C Standard has no explicit language prohibiting
lazy allocation. However, the Standard *does* say that if
malloc(non_zero_size) returns a non-NULL pointer, then all
the `non_zero_size' bytes are available for storing data.
An implementation that allows
int *p = malloc(sizeof *p);
if (p != NULL) *p = 42;
to fail is not a conforming implementation.
Of course, the same thing can be said about the ^C key,
CPU time limits, and pulling the electric plug: All these
things and more can cause a C program to stop when the Standard
says it should still be running, so all of them make the
implementation non-conforming. "Usefully non-conforming," one
might say, which leads one to wonder why lazy allocation should
be singled out as Bad when control-C is recognized as Good ...
Personally, I am in the "lazy allocation is Bad" camp.
But I recognize that the infidels on the other side are not
completely devoid of reason.
--
Eric.Sosman@sun.com
[ Post a follow-up to this message ]
|