3 ms·
Yes, and consider char* c = malloc(...); char* d = c+ 100; malloc_size(d); Perfectly cromulent C, and I submit the result of the call is not what you might
by RogerL 13y ago
Yes, and consider
char* c = malloc(...);
char* d = c+ 100;
malloc_size(d);
Perfectly cromulent C, and I submit the result of the call is not what you might hope it will be.
The article is correct. There is no way in the C language to get the size of the array. Any implementation is, of course, free to build in anything extra in the memory allocator, but it is not part of the language. Specifically, you cannot add anything to the array itself, because memory layout is prescribed. ptr[0] must point to the first byte of memory that was allocated, and if you added some kind of table you'd be pointing to that.