• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

c standards with regard to pointer behavior

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
catbutt
Asked:
catbutt
  • 2
1 Solution
 
sunnycoderCommented:
Hi catbutt,

*a = *b should be fine

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

memmove ( a,b .. )  will be fine

Sunnycoder
0
 
catbuttAuthor Commented:
I'm so impressed with the speed of your answer (2 minutes) that I'll tack on a few more points. :)  
0
 
sunnycoderCommented:
:o)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now