resolved: difference between memcpy and memmove

Discussion in 'C Programming' started by Mike Wahler, Sep 27, 2003.

  1. Mike Wahler

    Mike Wahler Guest

    "Mac" <> wrote in message
    news:p...
    > $ cat junk27.c
    > #include <stdio.h>
    > #include <string.h>


    You don't need this header.

    >
    > int main (void)
    > {
    > printf("The difference between memcpy and memmove is %ld\n",
    > (long int) memcpy - (long int) memmove);


    Note: This is not portable. But if I wanted to do this,
    I'd use 'unsigned long' or 'unsigned long long'.

    6.3.2.3 Pointers

    6 Any pointer type may be converted to an integer type.
    Except as previously specified, the result is implementation-
    defined. If the result cannot be represented in the integer type,
    the behavior is undefined. The result need not be in the range
    of values of any integer type.

    AFAICT, 'previously specified' only refers to:

    6.3.2.3

    3 An integer constant expression with the value 0, or such
    an expression cast to type void *, is called a null pointer
    constant. If a null pointer constant is converted to a
    pointer type, the resulting pointer, called a null pointer,
    is guaranteed to compare unequal to a pointer to any object
    or function.

    > return 0;
    > }


    -Mike
     
    Mike Wahler, Sep 27, 2003
    #1
    1. Advertising

  2. Mike Wahler

    Mac Guest

    $ cat junk27.c
    #include <stdio.h>
    #include <string.h>

    int main (void)
    {
    printf("The difference between memcpy and memmove is %ld\n",
    (long int) memcpy - (long int) memmove);
    return 0;
    }

    $ make junk27
    cc -Wall -ansi -pedantic junk27.c -o junk27

    $ ./junk27
    The difference between memcpy and memmove is 48
    $


    So now we can put that behind us.

    Mac
    --
     
    Mac, Sep 27, 2003
    #2
    1. Advertising

  3. Mike Wahler wrote:
    > "Mac" <> wrote in message
    > news:p...
    >
    >>$ cat junk27.c
    >>#include <stdio.h>
    >>#include <string.h>

    >
    > You don't need this header.
    >

    Are you so sure ? Seems to me that without it, memcpy and memmove are
    undeclared identifiers...
    >
    >>int main (void)
    >>{
    >> printf("The difference between memcpy and memmove is %ld\n",
    >> (long int) memcpy - (long int) memmove);

    >


    --
    Bertrand Mollinier Toublet
    Blog: http://www.bmt.dnsalias.org/blog
     
    Bertrand Mollinier Toublet, Sep 27, 2003
    #3
  4. Mac wrote:

    > $ cat junk27.c
    > #include <stdio.h>
    > #include <string.h>
    >
    > int main (void)
    > {
    > printf("The difference between memcpy and memmove is %ld\n",
    > (long int) memcpy - (long int) memmove);
    > return 0;
    > }


    That's the first comp.lang.c article to make me GLOL for quite a while.

    (Where has all the humour gone?)

    --
    Richard Heathfield :
    "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
    C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
    K&R answers, C books, etc: http://users.powernet.co.uk/eton
     
    Richard Heathfield, Sep 27, 2003
    #4
  5. Mike Wahler

    Mike Wahler Guest

    "Bertrand Mollinier Toublet"
    <> wrote in message
    news:bl379f$7gvpj$-berlin.de...
    > Mike Wahler wrote:
    > > "Mac" <> wrote in message
    > > news:p...
    > >
    > >>$ cat junk27.c
    > >>#include <stdio.h>
    > >>#include <string.h>

    > >
    > > You don't need this header.
    > >

    > Are you so sure ? Seems to me that without it, memcpy and memmove are
    > undeclared identifiers...


    You are now authorized to beat me over the head
    with an undeclared identifier until my behavior
    becomes well-defined. :)

    -Mike
     
    Mike Wahler, Sep 27, 2003
    #5
  6. "Mac" <> wrote:

    >$ cat junk27.c
    >#include <stdio.h>
    >#include <string.h>
    >
    >int main (void)
    >{
    > printf("The difference between memcpy and memmove is %ld\n",
    > (long int) memcpy - (long int) memmove);
    > return 0;
    >}
    >
    >$ make junk27
    >cc -Wall -ansi -pedantic junk27.c -o junk27
    >
    >$ ./junk27
    >The difference between memcpy and memmove is 48
    >$
    >

    *LOL*

    Well, it's 16 on my implementation, which is one third of your result.
    Does this mean the relation between memcpy and memmove is three times
    closer on my system?

    Irrwahn
    --
    Computer: a million morons working at the speed of light.
     
    Irrwahn Grausewitz, Sep 27, 2003
    #6
  7. Richard Heathfield <> wrote:

    >(Where has all the humour gone?)


    The what?
    --
    Computer: a million morons working at the speed of light.
     
    Irrwahn Grausewitz, Sep 27, 2003
    #7
  8. Mike Wahler

    Mike Wahler Guest

    "Irrwahn Grausewitz" <> wrote in message
    news:eek:...
    > "Mac" <> wrote:
    >
    > >$ cat junk27.c
    > >#include <stdio.h>
    > >#include <string.h>
    > >
    > >int main (void)
    > >{
    > > printf("The difference between memcpy and memmove is %ld\n",
    > > (long int) memcpy - (long int) memmove);
    > > return 0;
    > >}
    > >
    > >$ make junk27
    > >cc -Wall -ansi -pedantic junk27.c -o junk27
    > >
    > >$ ./junk27
    > >The difference between memcpy and memmove is 48
    > >$
    > >

    > *LOL*
    >
    > Well, it's 16 on my implementation, which is one third of your result.
    > Does this mean the relation between memcpy and memmove is three times
    > closer on my system?


    If the relation is expressed in distance using
    memory addresses, then it's 66.67% closer.

    -Mike
     
    Mike Wahler, Sep 27, 2003
    #8
  9. On Sat, 27 Sep 2003, Mike Wahler wrote:
    >
    > "Irrwahn Grausewitz" <> wrote in message
    > news:eek:...
    > > "Mac" <> wrote:
    > >
    > > >$ ./junk27
    > > >The difference between memcpy and memmove is 48

    > >
    > > *LOL*
    > > Well, it's 16 on my implementation, which is one third of your result.
    > > Does this mean the relation between memcpy and memmove is three times
    > > closer on my system?

    >
    > If the relation is expressed in distance using
    > memory addresses, then it's 66.67% closer.


    No, it's 66.67% *less far*. It's still three times *closer*,
    using the traditional metric

    closity = 1.0 / farthitude

    :)

    -Arthur
     
    Arthur J. O'Dwyer, Sep 27, 2003
    #9
  10. Mike Wahler

    Ben Pfaff Guest

    "Mike Wahler" <> writes:

    > > printf("The difference between memcpy and memmove is %ld\n",
    > > (long int) memcpy - (long int) memmove);

    >
    > Note: This is not portable. But if I wanted to do this,
    > I'd use 'unsigned long' or 'unsigned long long'.


    For what it's worth, C99 has intptr_t and uintptr_t in
    <stdint.h>. But they are optional and don't apply to function
    pointers anyway.
    --
    "Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are,
    by definition, not smart enough to debug it."
    --Brian Kernighan
     
    Ben Pfaff, Sep 27, 2003
    #10
  11. Mac wrote:
    > $ cat junk27.c
    > #include <stdio.h>
    > #include <string.h>
    >
    > int main (void)
    > {
    > printf("The difference between memcpy and memmove is %ld\n",
    > (long int) memcpy - (long int) memmove);
    > return 0;
    > }
    >
    > $ make junk27
    > cc -Wall -ansi -pedantic junk27.c -o junk27
    >
    > $ ./junk27
    > The difference between memcpy and memmove is 48
    > $
    >


    Too bad :(
    I hoped it would be 42...


    Bruno
     
    Bruno Desthuilliers, Sep 28, 2003
    #11
  12. Bruno Desthuilliers <> writes:
    > Mac wrote:

    [...]
    > > The difference between memcpy and memmove is 48
    > > $

    >
    > Too bad :(
    > I hoped it would be 42...


    You want 42?

    #include <stdio.h>

    #define SIX 1+5
    #define NINE 8+1

    int main(void)
    {
    printf("%d * %d = %d\n", SIX, NINE, SIX * NINE);
    return 0;
    }

    (Not original; I don't remember where I got it.)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
    Schroedinger does Shakespeare: "To be *and* not to be"
     
    Keith Thompson, Sep 29, 2003
    #12
  13. Keith Thompson wrote:
    > Bruno Desthuilliers <> writes:
    >
    >>Mac wrote:

    >
    > [...]
    >
    >>>The difference between memcpy and memmove is 48
    >>>$

    >>
    >>Too bad :(
    >>I hoped it would be 42...

    >
    >
    > You want 42?
    >
    > #include <stdio.h>
    >
    > #define SIX 1+5
    > #define NINE 8+1
    >
    > int main(void)
    > {
    > printf("%d * %d = %d\n", SIX, NINE, SIX * NINE);
    > return 0;
    > }
    >
    > (Not original; I don't remember where I got it.)
    >


    Yep, but this only gives you the answer. What we're looking for here is
    the question...
     
    Bruno Desthuilliers, Sep 29, 2003
    #13
  14. Bruno Desthuilliers <> writes:
    > Keith Thompson wrote:
    > > Bruno Desthuilliers <> writes:
    > >
    > >>Mac wrote:

    > > [...]
    > >
    > >>>The difference between memcpy and memmove is 48
    > >>>$
    > >>
    > >>Too bad :(
    > >>I hoped it would be 42...

    > > You want 42?
    > > #include <stdio.h>
    > > #define SIX 1+5
    > > #define NINE 8+1
    > > int main(void)
    > > {
    > > printf("%d * %d = %d\n", SIX, NINE, SIX * NINE);
    > > return 0;
    > > }
    > > (Not original; I don't remember where I got it.)
    > >

    >
    > Yep, but this only gives you the answer. What we're looking for here
    > is the question...


    41?

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
    Schroedinger does Shakespeare: "To be *and* not to be"
     
    Keith Thompson, Sep 29, 2003
    #14
  15. Mike Wahler

    Mike Wahler Guest

    "Bruno Desthuilliers" <> wrote in message
    news:3f7833b4$0$27579$...
    > Keith Thompson wrote:
    > > Bruno Desthuilliers <> writes:
    > >
    > >>Mac wrote:

    > >
    > > [...]
    > >
    > >>>The difference between memcpy and memmove is 48
    > >>>$
    > >>
    > >>Too bad :(
    > >>I hoped it would be 42...

    > >
    > >
    > > You want 42?
    > >
    > > #include <stdio.h>
    > >
    > > #define SIX 1+5
    > > #define NINE 8+1
    > >
    > > int main(void)
    > > {
    > > printf("%d * %d = %d\n", SIX, NINE, SIX * NINE);
    > > return 0;
    > > }
    > >
    > > (Not original; I don't remember where I got it.)
    > >

    >
    > Yep, but this only gives you the answer. What we're looking for here is
    > the question...


    ?eip a ni dekab sdribkcalb ynam owH

    :)

    -Mike
     
    Mike Wahler, Sep 29, 2003
    #15
  16. Mike Wahler

    CBFalconer Guest

    Mike Wahler wrote:
    >

    .... snip ...
    >
    > ?eip a ni dekab sdribkcalb ynam owH
    >
    > :)


    ?? owH

    --
    Chuck F () ()
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net> USE worldnet address!
     
    CBFalconer, Sep 30, 2003
    #16
  17. Mike Wahler

    goose Guest

    "Mike Wahler" <> wrote in message news:<YO1eb.8094$>...
    > "Bruno Desthuilliers" <> wrote in message
    > news:3f7833b4$0$27579$...
    > > Keith Thompson wrote:
    > > > Bruno Desthuilliers <> writes:
    > > >
    > > >>Mac wrote:
    > > >
    > > > [...]
    > > >
    > > >>>The difference between memcpy and memmove is 48
    > > >>>$
    > > >>
    > > >>Too bad :(
    > > >>I hoped it would be 42...
    > > >
    > > >
    > > > You want 42?
    > > >
    > > > #include <stdio.h>
    > > >
    > > > #define SIX 1+5
    > > > #define NINE 8+1
    > > >
    > > > int main(void)
    > > > {
    > > > printf("%d * %d = %d\n", SIX, NINE, SIX * NINE);
    > > > return 0;
    > > > }
    > > >
    > > > (Not original; I don't remember where I got it.)
    > > >

    > >
    > > Yep, but this only gives you the answer. What we're looking for here is
    > > the question...

    >
    > ?eip a ni dekab sdribkcalb ynam owH
    >
    > :)
    >


    shouldn't that end with "woH" ?
    (am i the only one who, when reading backwards, tend to
    mix up the b and d chars ? i read that first as dlackdirbs :)


    goose,
    "we apologise for the inconvenience" is what I am aiming for :)
     
    goose, Sep 30, 2003
    #17
  18. Mike Wahler

    Mike Wahler Guest

    "CBFalconer" <> wrote in message
    news:...
    > Mike Wahler wrote:
    > >

    > ... snip ...
    > >
    > > ?eip a ni dekab sdribkcalb ynam owH
    > >
    > > :)

    >
    > ?? owH


    )-: .timmaD .opyT

    -Mike
     
    Mike Wahler, Sep 30, 2003
    #18
  19. Mike Wahler

    Jirka Klaue Guest

    Mike Wahler wrote:
    >"CBFalconer" <> wrote:
    >>Mike Wahler wrote:
    >>
    >>>?eip a ni dekab sdribkcalb ynam owH
    >>>
    >>>:)

    >>
    >>?? owH

    >
    > )-: .timmaD .opyT


    ?(-: a ro )-: a eb ot desoppus siht sI

    Jirka
     
    Jirka Klaue, Sep 30, 2003
    #19
  20. Jirka Klaue <-berlin.de> scribbled the following:
    > Mike Wahler wrote:
    >>"CBFalconer" <> wrote:
    >>>Mike Wahler wrote:
    >>>
    >>>>?eip a ni dekab sdribkcalb ynam owH
    >>>>
    >>>>:)
    >>>
    >>>?? owH

    >>
    >> )-: .timmaD .opyT


    > ?(-: a ro )-: a eb ot desoppus siht sI


    ?siht ekil gnitirw nehw (-: dna )-: neetweb ecnereffid eht si tahw dnA

    --
    /-- Joona Palaste () ---------------------------\
    | Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
    | http://www.helsinki.fi/~palaste W++ B OP+ |
    \----------------------------------------- Finland rules! ------------/
    "That's no raisin - it's an ALIEN!"
    - Tourist in MTV's Oddities
     
    Joona I Palaste, Sep 30, 2003
    #20
    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. Replies:
    2
    Views:
    11,373
    Gianni Mariani
    Feb 14, 2005
  2. novice

    diff memcpy and memmove

    novice, Mar 10, 2006, in forum: C Programming
    Replies:
    8
    Views:
    751
    Default User
    Mar 10, 2006
  3. somenath

    Question regarding memcpy and memmove function

    somenath, Sep 2, 2007, in forum: C Programming
    Replies:
    16
    Views:
    794
    somenath
    Sep 4, 2007
  4. Noob

    Re: memcpy and memmove

    Noob, Apr 3, 2013, in forum: C Programming
    Replies:
    0
    Views:
    171
  5. Malcolm McLean

    Re: memcpy and memmove

    Malcolm McLean, Apr 3, 2013, in forum: C Programming
    Replies:
    0
    Views:
    173
    Malcolm McLean
    Apr 3, 2013
Loading...

Share This Page