[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

c standards with regard to pointer behavior

Posted on 2004-03-23
3
Medium Priority
?
370 Views
Last Modified: 2010-04-15
If i have two pointers to structures a and b, like this:

Thing *a, *b;

I can copy the contents of the Thing pointed to by b to a like so:

*a = *b;

(which is basically the same as memcpy (a, b, sizeof(*a))...)

So the question is, what if a and b both point to exact same location?  Is the behavior undefined, or should it leave the contents unchanged as you would expect?

I can test it easily, but i want to know if it is guaranteed portable.
0
Comment
Question by:catbutt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 300 total points
ID: 10664771
Hi catbutt,

*a = *b should be fine

memcpy ( a,b, sizof (Thing) ) is undefined

memmove ( a,b .. )  will be fine

Sunnycoder
0
 
LVL 1

Author Comment

by:catbutt
ID: 10664793
I'm so impressed with the speed of your answer (2 minutes) that I'll tack on a few more points. :)  
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10664800
:o)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question