Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
#include problem
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="James Kuyper, post: 4245862"] Well, in this particular, case, as previously mentioned, a2 = a1 is clearly better than any use of memcpy(). However, in the more general case where a simple assignment statement is not a viable alternative, I can't really make a strong argument for "sizeof destination" over "sizeof source". Writing too much is slightly more likely to be dangerous than reading too much, but I won't claim that this is a strong argument. However, I strongly prefer either one to "sizeof(type)". There's two closely related reasons for that preference: it allows me to change the types of the source and destination (as long as both are the same) without having to re-write the call to memcpy(). The other, and in my opinion, most important reason, is that I can confirm that the size is correct just by looking at the memcpy() call, I don't need to check backwards to the declaration of the destination to confirm that it is in fact of type 'struct my'. In principle, it would be better to make sure that both the source and destination have the same size as that used in the copy; but that would make the code substantially more clumsy - I don't think it's worth the effort. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
#include problem
Top