By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,952 Members | 1,411 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,952 IT Pros & Developers. It's quick & easy.

memcpy src & dst same

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
"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 discussion thread is closed

Replies have been disabled for this discussion.