for copying structs, for most compilers, this seems like a "more likely correct" solution (ex: if memcpy is handled poorly, ...).
-
-
Replying to @cr88192 @RichFelker
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.
1 reply 0 retweets 0 likes -
Replying to @sortiecat @cr88192
Huh? Of course C has struct assignment by value.
1 reply 0 retweets 1 like -
Replying to @RichFelker @cr88192
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.
2 replies 0 retweets 1 like -
Replying to @sortiecat @cr88192
Yes. But memcmp for structs is often wrong unless you know they have no padding, & no members that need comparison more nuanced than memcmp.
1 reply 0 retweets 1 like -
Replying to @RichFelker @cr88192
I continue to be terrified of bugs relating to uninitialized padding and struct uninitialized padding copied between security boundaries
1 reply 1 retweet 2 likes -
Replying to @sortiecat @cr88192
This is a strong argument for not copying structs at all but just assigning individual members.
1 reply 0 retweets 2 likes -
Replying to @RichFelker @cr88192
struct foo a = b; struct foo a = { 0 }; a.baz = b.baz; a.qux = b.qux; Much more boilerplate. :/
2 replies 0 retweets 1 like -
Does { 0 } promise to initialize padding to 0? Or do I need memset for that?
2 replies 0 retweets 2 likes -
IIRC, C11 only mentions that each aggregate will be initialized using same rules as things with static storage. It doesn't mention padding.
2 replies 0 retweets 0 likes
IIRC there is a rule about zeroing padding in some cases but I don't remember where.
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.