I am not so well-versed in the C standard, so please bear with me.
I would like to know if it is guaranteed, by the standard, that memcpy(0,0,0) is safe.
The only restriction I could find is that if the memory regions overlap, then the behavior is undefined…
But can we consider that the memory regions overlap here ?
I have a draft version of the C standard (ISO/IEC 9899:1999), and it has some fun things to say about that call. For starters, it mentions (§7.21.1/2) in regards to
memcpythatThe reference indicated here points to this:
So it looks like according to the C spec, calling
results in undefined behavior, because null pointers are considered “invalid values.”
That said, I would be utterly astonished if any actual implementation of
memcpybroke if you did this, since most of the intuitive implementations I can think of would do nothing at all if you said to copy zero bytes.