473,796 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

resolved: difference between memcpy and memmove

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
--
Nov 13 '05 #1
21 5546
"Mac" <fo*@bar.net> wrote in message
news:pa******** *************** *****@bar.net.. .
$ 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
Nov 13 '05 #2
Mike Wahler wrote:
"Mac" <fo*@bar.net> wrote in message
news:pa******** *************** *****@bar.net.. .
$ 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

Nov 13 '05 #3
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 : bi****@eton.pow ernet.co.uk
"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
Nov 13 '05 #4

"Bertrand Mollinier Toublet"
<be************ *************** **@enst-bretagne.fr> wrote in message
news:bl******** ****@ID-168218.news.uni-berlin.de...
Mike Wahler wrote:
"Mac" <fo*@bar.net> wrote in message
news:pa******** *************** *****@bar.net.. .
$ 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
Nov 13 '05 #5
"Mac" <fo*@bar.net> 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.
Nov 13 '05 #6
Richard Heathfield <do******@addre ss.co.uk.invali d> wrote:
(Where has all the humour gone?)


The what?
--
Computer: a million morons working at the speed of light.
Nov 13 '05 #7

"Irrwahn Grausewitz" <ir************ *****@freenet.d e> wrote in message
news:o2******** *************** *********@4ax.c om...
"Mac" <fo*@bar.net> 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
Nov 13 '05 #8

On Sat, 27 Sep 2003, Mike Wahler wrote:

"Irrwahn Grausewitz" <ir************ *****@freenet.d e> wrote in message
news:o2******** *************** *********@4ax.c om...
"Mac" <fo*@bar.net> 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
Nov 13 '05 #9
"Mike Wahler" <mk******@mkwah ler.net> 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
Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
17516
by: franky.backeljauw | last post by:
Hello, following my question on "std::copy versus pointer copy versus member copy", I had some doubts on the function memcpy, as was used by tom_usenet in his reply. - Is this a c++ standard library function? That is, can I be sure that every c++ standard library has this function? Or is there a c++ alternative to it?
7
33443
by: bisforbenson | last post by:
I'm trying to compile things with gcc 4. After running the following command: % gcc -O3 -g -Wall -Wno-unused -DLINUX -D_REENTRANT -o ../../obj/egi.o -I../../include/ -I... -c egi.cpp i get the following errors: /usr/lib/gcc/i386-redhat-linux/4.0.1/../../../../include/c++/4.0.1/cstring:79: error: '::memcpy' has not been declared
35
12064
by: Christopher Benson-Manica | last post by:
(if this is a FAQ or in K&R2, I didn't find it) What parameters (if any) may be 0 or NULL? IOW, which of the following statements are guaranteed to produce well-defined behavior? char src; char dst; memcpy( dst, src, 1 ); memcpy( NULL, src, 1 );
5
18784
by: xdevel | last post by:
Hi, anyone can make me an example where memmove does not cause a memory overlapping and where memcpy do it? Thanks
14
2807
by: somenath | last post by:
Hi All, I am trying to understand the behavior of the memcpy and memmove. While doing so I wrote a program as mentioned bellow . #include<stdio.h> #include<stdlib.h> #include<string.h> #define SIZE_OF_DST 3 int main(void)
8
5233
by: mthread | last post by:
Hi, I am copying data from one buffer(this data is a binary data not string) to another buffer. Earlier when I used C, I used the memcpy function call to copy the values. Is there any equivalent replacement in C++ for this call.
4
3410
by: gsi | last post by:
Hi all, memmove() is guranteed to work correctly if the objects overlap, I am not sure why this can't be done without any extra condition check in code for the memmove() implementation or why would memcpy() fail in this situation. Please advice. Thanks in advance, Gsi.
18
2716
by: sam | last post by:
(newbie)Technically what's the difference between memset() and memcpy() functions?
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10467
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10244
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10201
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.