Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Re: memcopy, memmove Implementation (http://www.velocityreviews.com/forums/t313768-re-memcopy-memmove-implementation.html)

Dan Pop 06-24-2003 12:26 PM

Re: memcopy, memmove Implementation
 
In <3EF78712.289@mindspring.com> pete <pfiland@mindspring.com> writes:

>Richard Heathfield wrote:
>
>> So yes, the object pointed to by bar is indeed changed by memmove,
>> despite the const. BUT of course the behaviour is still well-defined,
>> because at no point is memmove having to write to anything
>> other than a modifiable lvalue.

>
>Even if the s2 parameter, were not const qualified,
>there is still enough information in the standard
>to make the determination that
>
> memcpy(s1, "source", sizeof "source")
>
>is a valid call, assuming only that s1 points to
>something writeable and big enough.
>That means there's also enough information in the standard
>to let the implementor of memcpy() know that
>memcpy() has to be able to handle a call like that.


The const in the declaration of s2 serves a completely different
purpose. Consider the slightly modified version of your call:

memcpy(s1, (const char *)"source", sizeof "source")

If s2 were not const qualified, such code would require a diagnostic,
because the const would be lost when converting the second argument of
the memcpy call to the type of s2.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de

pete 06-24-2003 01:42 PM

Re: memcopy, memmove Implementation
 
Dan Pop wrote:
>
> In <3EF78712.289@mindspring.com> pete <pfiland@mindspring.com> writes:
>
> >Richard Heathfield wrote:
> >
> >> So yes, the object pointed to by bar is indeed changed by memmove,
> >> despite the const.
> >> BUT of course the behaviour is still well-defined,
> >> because at no point is memmove having to write to anything
> >> other than a modifiable lvalue.

> >
> >Even if the s2 parameter, were not const qualified,
> >there is still enough information in the standard
> >to make the determination that
> >
> > memcpy(s1, "source", sizeof "source")
> >
> >is a valid call, assuming only that s1 points to
> >something writeable and big enough.
> >That means there's also enough information in the standard
> >to let the implementor of memcpy() know that
> >memcpy() has to be able to handle a call like that.

>
> The const in the declaration of s2 serves a completely different
> purpose. Consider the slightly modified version of your call:
>
> memcpy(s1, (const char *)"source", sizeof "source")
>
> If s2 were not const qualified, such code would require a diagnostic,
> because the const would be lost when converting the second argument of
> the memcpy call to the type of s2.


OK.

--
pete


All times are GMT. The time now is 10:12 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.