Is there any C warning for memcmp(a, b, sizeof(type)) if either *a and *b are not of the type (or if struct doesn't start with type, etc)?
-
-
for copying structs, for most compilers, this seems like a "more likely correct" solution (ex: if memcpy is handled poorly, ...).
-
Yes, exactly. Unfortunately C doesn't have struct assignment by value, which is a shame. Feels like a C-y operation to me and not C++-like.
-
Huh? Of course C has struct assignment by value.
-
Huh. You're right. Not sure where I got this impression from. Yay. Though C doesn't have struct == so my memcmp concerns still exist.
-
Type-checking memcpy(a, b, sizeof(*a)) is *a = *b. Type-checking memcmp(a, b, sizeof(*a)) is (a == b & 0) || memcmp(a, b, sizeof(a)). Cool!
-
The & 0 can be removed if you're sure a != b or do a == b || memcmp(a, b, sizeof(*a)) == 0 to check for a true comparison condition.
-
!= should work fine too.
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.