4 ms·
> But one can dream ... There's nothing stopping you from simply doing it. With a couple of macros the whole thing can just be a header file. True, it doesn't
by ars 8y ago
> But one can dream ...
There's nothing stopping you from simply doing it. With a couple of macros the whole thing can just be a header file.
True, it doesn't take you all the way there (you'll still need to manually check array access to make sure they don't go over), but it's a start. And those manual checks can be a macro as well, to make it easy to add them where needed.
- slededit 8y agoMalloc already includes a length and most arrays are heap based. I wish it could be exposed in a nice way. Of course it would have to support sub allocators or it wouldn't be C.
- ric129 8y agoThere's malloc_usable_size[1], assuming you mean asking the memory allocator what the array size is. But chances are that wouldn't work correctly, because what the amount of memory a malloc calls gives you and the amount you requested are often not the same. Modern memory allocators round up the request size to the nearest "size class". [1]: http://man7.org/linux/man-pages/man3/malloc_usable_size.3.html http://man7.org/linux/man-pages/man3/malloc_usable_size.3.ht...