Well, I didn't think of your way, but both ways work.

I think the use of 'memmove' instead of 'memcpy' is a little
more obscure, and I personally try to avoid 'realloc' in
general, just because of the contortions through which one
has to go in order to do proper error-checking.
But your (Chris's) way works, and I bet there are sane
people out there who prefer it over mine.
I'm assuming that here you mean free(tmp);
Probably Chris meant to insert an
else { p = tmp; }
three lines up, instead.
I havn't been able to make it core dump but shouldn't it?
Of course not!
When you realloc to a large enough size that you have to create a
whole new area,
Strictly speaking, you may never *ever* have to "create a whole new
area." malloc() could just give you these really gi-normous blocks
of memory to begin with.
shouldn't the vm_struct be destroyed
C has no concept of "vm_struct", unless you, the programmer,
decide to define one in your own code.
and memory be
copied on write to the new region? Assuming linux is posix compliant
for realloc,
Linux is off-topic for c.l.c. So is POSIX. And as far as I know,
the behavior of 'realloc' is not defined or extended in any way by
POSIX anyway. [No, I *don't* care.]
then it *should* apply in a similar manner to all other
posix compliant os's. I'm not certain about linux's functionality,
my book is at home.
Turns out you don't need it in this newsgroup; the Book here
is K&R2, and the Final Authority is the ISO standard. You wanna
talk POSIX or vm_structs or whatever, go to a newsgroup where
people talk about that stuff.
HTH,
-Arthur