4 ms·
Manual says > If size is 0, then malloc() returns either NULL, or a unique pointer value that can later be successfully passed to free(). So it's not really a
by enedil 5y ago
Manual says
> If size is 0, then malloc() returns either NULL, or a unique pointer value that can later be successfully passed to free().
So it's not really an array of bytes of size 0.
- MichaelBurge 5y agoWhat qualifies something as a "real" array of bytes? All RAM is an array of bytes, so any pointer to real memory(vs. virtual memory) is a pointer to an array of bytes.
- enedil 5y agoC mandates that arrays have positive size. It's not really a discussion about what the target platform does, rather it's what the abstract C machine mandates.
- MichaelBurge 5y agoOh sure - malloc() returns a pointer to sequentially-addressable bytes, not a C array. So even if the size were greater than 0, it would prove nothing about C arrays.
- minipci1321 5y ago> ... malloc() returns a pointer to sequentially-addressable bytes ... malloc () doesn't return even that. It returns 'void *' which isn't of much use without a further upcast. The required upcast, and the rest that follows, is the coder's own idea of what happens.
- robotresearcher 5y agoThe second allowed result of malloc(0), a unique pointer passable to free(), is not a pointer to an array of bytes. It can’t be used to access bytes - only compared to other pointers since it’s unique, and passed to free(). It doesn’t point to anything.