473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

memcpy src & dst same

clu
If the source and destination pointers happen to be the same during a
memcpy(), is that going to cause undefined behavior?

int *src = &myarr[0];
int *dst = &myarr[0];

memcpy( dst, src, sizeof(myarr) );

--
clu

Nov 15 '05 #1
2 6408
clu wrote:
If the source and destination pointers happen to be the same during a
memcpy(), is that going to cause undefined behavior?

int *src = &myarr[0];
int *dst = &myarr[0];

memcpy( dst, src, sizeof(myarr) );


Yes. 7.21.2.1p2 "... If copying takes place between objects that
overlap, the behavior is undefined."

--
Peter

Nov 15 '05 #2
"clu" <sc*****@gmail.com> wrote:
If the source and destination pointers happen to be the same during a
memcpy(), is that going to cause undefined behavior?

int *src = &myarr[0];
int *dst = &myarr[0];

memcpy( dst, src, sizeof(myarr) );


Yes. If this is a problem, use memmove() instead.

Richard
Nov 15 '05 #3

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

Similar topics

10
by: spoc | last post by:
I have been using memcpy to copy one class to another of the same type. There are reasons why I had to do this bug am getting some odd crashes and maybe I'm doing something dodgy copying classes...
2
by: Paul Schouten | last post by:
Hey, Currently im working on a project where a dynamic database is created in memory, the database can be of any size both in the amount of rows aswell as in the amount of columns. The database...
2
by: ronny | last post by:
Can anyone tell me why the following code works fine using an array. <snip> double xVal; // array mxArray *X = NULL; //MatLab mxArrays
3
by: ishmael4 | last post by:
I dont know what to do with this function. It separates a block of binary data into blocks, and then deals with the rest of binary (les than 5000 bytes). Here we go: --cut here-- void...
33
by: Case | last post by:
#define SIZE 100 #define USE_MEMCPY int main(void) { char a; char b; int n; /* code 'filling' a */
6
by: myhotline | last post by:
hi all im very confused about using memcpy and i have three questions....memcpy takes a pointer to src and a pointer to dest and copies src to destination...but im very confuzed about when to...
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
8
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...
11
by: mthread | last post by:
Hi, I would like to know if C++ has a class equivalent to memcpy and its associated functions available in C.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...

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.