Question 7.30

Is it legal to pass a null pointer as the first argument to realloc? Why would you want to?


ANSI C sanctions this usage (and the related realloc(..., 0), which frees), although several earlier implementations do not support it, so it may not be fully portable. Passing an initially-null pointer to realloc can make it easier to write a self-starting incremental allocation algorithm.

References: ANSI Sec. 4.10.3.4
ISO Sec. 7.10.3.4
H&S Sec. 16.3 p. 388


Read sequentially: prev next up top


This page by Steve Summit // Copyright 1995 // mail feedback