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. Here is an example–this function reads an arbitrarily-long line into dynamically-allocated memory, reallocating the input buffer as necessary. (The caller must free the returned pointer when it is no longer needed.) #include