resolved: difference between memcpy and memmove

M

Mike Wahler

Mac said:
$ 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
 
M

Mac

$ 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
--
 
R

Richard Heathfield

Mac said:
$ 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?)
 
M

Mike Wahler

"Bertrand Mollinier Toublet"
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
 
I

Irrwahn Grausewitz

Mac said:
$ 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
 
M

Mike Wahler

Irrwahn Grausewitz said:
*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
 
A

Arthur J. O'Dwyer

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
 
B

Ben Pfaff

Mike Wahler said:
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.
 
B

Bruno Desthuilliers

Mac said:
$ 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
 
K

Keith Thompson

Bruno Desthuilliers said:
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.)
 
B

Bruno Desthuilliers

Keith said:
Bruno Desthuilliers said:
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...
 
K

Keith Thompson

Bruno Desthuilliers said:
Keith said:
Bruno Desthuilliers said:
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?
 
M

Mike Wahler

Bruno Desthuilliers said:
Keith said:
Bruno Desthuilliers said:
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
 
G

goose

Mike Wahler said:
Bruno Desthuilliers said:
Keith said:
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 :)
 
J

Joona I Palaste

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

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

--
/-- Joona Palaste ([email protected]) ---------------------------\
| 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top