3 ms·
You don't even need malloc: just expose the address of the first element of the array (i.e. "erase" the size) instead of presenting the whole backing array, siz
by saagarjha 8y ago
You don't even need malloc: just expose the address of the first element of the array (i.e. "erase" the size) instead of presenting the whole backing array, size and all. The issue here, of course, is that you can no longer use sizeof.
- jschwartzi 8y agoYeah, I'm really surprised that anyone would even use an array across object boundaries like this. I've never been in a situation where that would be preferable to providing a pointer and a size_t instead. It's been far more common throughout my career to do it that way instead of how the author is describing.
- klodolph 8y agoHow would you do that? The problem is that: extern int my_array[]; appears to expose only the address of the first element and not the size, but in fact the size is exposed through the linker.