John Love-Jensen wrote:
Hi Robert, Can you just get rid of the void** for the items parameter (see below)? --Eljay #include <stdlib.h> int reallocItems( void* items, int itemSize, int* itemAlloc, int numItems, int newItems, int itemHint) { void* rcAlloc; int emptyItems; int allocItems; // for idempotence allocItems = *itemAlloc; // will the new entries fit? emptyItems = allocItems - numItems; if (newItems > emptyItems) { // allocate the number of entries needed or the hint, whichever is more allocItems = numItems + newItems; if (itemHint > allocItems) { allocItems = itemHint; } rcAlloc = realloc(items, allocItems * itemSize); if (rcAlloc) { *(void**)items = rcAlloc; *itemAlloc = allocItems; } else { return -1; } } return 0; }
Would this circumvent the type system? Is there still an alias problem with your suggestion, albeit without a warning? I am not sure.
Rob