incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: Null src pointer in memcpy?
Date Fri, 11 Apr 2008 01:20:44 GMT
Eric Lemings wrote:
>  
> Is it safe to pass a null pointer as the 2nd argument to memcpy()?  Or
> undefined?

Assuming the third argument is 0. Strictly speaking I believe it's
undefined because memcpy(s1, s2, n) is specified to "copy n bytes
from the object pointed to by s2 into the object pointed to by s1"
and a null pointer doesn't point to an object. An object is defined
as "a region of storage in the execution environment, the contents
of which can represent values."

AFAIK, most implementations allow null pointers for no-op calls to
memcpy() but gcc issues a warning when it detects at compile time
that a null pointer is passed as the first or second argument to
memcpy().

Martin


Mime
View raw message