On Mon, Jan 19, 2004 at 05:48:38AM +0900, Hye-Shik Chang wrote: > Is there a particular reason for allocating zero-sized memory for > this? On my test, assigning NULL on self->ob_item instead is worked > either. Yes. I think that the explanation goes something like this: Only values returned by malloc/calloc/realloc are suitable as an argument to realloc/free. So, if you want to start with 0 bytes but not special case the deallocation or reallocation case, you write f = malloc(0); instead of f = NULL; later, you can use f = realloc(f, newsize); /* Ignoring error checking */ and f = free(f) instead of if (f) f = realloc(f, newsize); else f = malloc(newsize); and if(f) free(f); now, some systems have malloc(0) return NULL, and accept free(NULL) as a no-op, and realloc(NULL, newsize) as malloc(newsize), but behavior other than that is allowed by the C standard. Jeff
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4