Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: Intermediate
Jun 26, 2000

Restrictions on Using Memcpy()

You should use memcpy() only for copying POD (plain old data) types, but not class objects. For copying objects, use their assignment operator or the std::copy() algorithm. Remember also that the pointers passed to memcpy() must point to non-overlapping variables; otherwise, the results are undefined:

 
struct A
{
 int n;
};

A a;
memcpy(&a, &a, sizeof(A));//overlapping pointers; undefined
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap