Re: memcopy, memmove Implementation

Discussion in 'C Programming' started by Dan Pop, Jun 24, 2003.

  1. Dan Pop

    Dan Pop Guest

    In <> pete <> 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, Jun 24, 2003
    #1
    1. Advertising

  2. Dan Pop

    pete Guest

    Dan Pop wrote:
    >
    > In <> pete <> 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
    pete, Jun 24, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan Pop

    Re: memcopy, memmove Implementation

    Dan Pop, Jun 24, 2003, in forum: C Programming
    Replies:
    0
    Views:
    1,219
    Dan Pop
    Jun 24, 2003
  2. Micah Cowan

    Re: memcopy, memmove Implementation

    Micah Cowan, Jun 26, 2003, in forum: C Programming
    Replies:
    0
    Views:
    833
    Micah Cowan
    Jun 26, 2003
  3. Trewth Seeker

    Re: memcopy, memmove Implementation

    Trewth Seeker, Jul 14, 2003, in forum: C Programming
    Replies:
    0
    Views:
    512
    Trewth Seeker
    Jul 14, 2003
  4. Replies:
    15
    Views:
    636
    Jorgen Grahn
    Feb 1, 2007
  5. JeanDean
    Replies:
    2
    Views:
    324
    Grizlyk
    Feb 13, 2007
Loading...

Share This Page