Stephen said:
Are you saying that it is impossible to implement malloc() et al in
conforming C? Or just the extra features Trevor listed?
That's what he's said, but it's wrong - conforming C code has very few
limitations on what it can do (off hand, I can't think of any). If you
change "conforming" to "strictly conforming" his statement becomes more
accurate. The fundamental problem is that strictly conforming C programs
have only one possible mechanism for obtaining a pointer to a block of
memory that is guaranteed to have universal alignment (correct alignment
for all possible objects). That method is to call malloc(). If written
in strictly conforming C code, malloc() has no way to do that (a
recursive call to malloc() is obviously not a solution to the problem),
yet it is required by the standard to return such a pointer.
For practical purposes, an implementation of malloc() could be written
that allocates from a fixed static array of memory. The array would have
a union type, where the union has members of many different types. The
wider the variety of types in the union, the more likely it is to have
universal alignment. In practice, if the union contains short, int,
long, long long, float, double, long double, void*, and void(*)(void),
it's got a pretty good chance of having universal alignment. However,
there's no finite set of types which is guaranteed by the standard to
give such a union universal alignment.