Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: memcopy, memmove Implementation

Reply
Thread Tools

Re: memcopy, memmove Implementation

 
 
Dan Pop
Guest
Posts: n/a
 
      06-24-2003
In <(E-Mail Removed)> pete <(E-Mail Removed)> 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: http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
pete
Guest
Posts: n/a
 
      06-24-2003
Dan Pop wrote:
>
> In <(E-Mail Removed)> pete <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Memmove v/s Linked list Implementation getsanjay.sharma@gmail.com C Programming 15 02-01-2007 12:31 PM
memcpy verses memmove rinku24@yahoo.com C++ 2 02-14-2005 02:48 AM
Re: memcopy, memmove Implementation Trewth Seeker C Programming 0 07-14-2003 05:17 PM
Re: memcopy, memmove Implementation Micah Cowan C Programming 0 06-26-2003 02:52 AM
Re: memcopy, memmove Implementation Dan Pop C Programming 0 06-24-2003 12:17 PM



Advertisments