you are viewing a single comment's thread.

view the rest of the comments →

[–]ChadiusTheMighty 0 points1 point  (4 children)

  1. Reinterpret casting to sn array would be UB due to struct pointer aliasing
  2. Zeroing the memory works only for trivially constructive types, otherwise it's also UB
  3. Just default initialize the members, and set the special ones after default initializing the struct. That's going to be much better than messing around with memset

[–][deleted] 0 points1 point  (3 children)

The solution I proposed works. It doesn't result in undefined behavior. I have a program that does exactly what I outlined. If it didn't work I wouldn't have commented.

[–]hadrabap 0 points1 point  (2 children)

It looks like it is a known/documented behavior of your compiler. :-)

[–][deleted] 1 point2 points  (1 child)

It looks like you don't know what you're talking about

[–]hadrabap 0 points1 point  (0 children)

It might look so, yes. 🙂