2 ms·
That's really cool, but don't unassigned fields have undefined values? How would the function know what was set? I imagine that in practice they're almost alway
by jolmg 8y ago
That's really cool, but don't unassigned fields have undefined values? How would the function know what was set? I imagine that in practice they're almost always 0, but that's not guaranteed, right? You'd need to set the struct as {0}, to have everything be 0. Is this a feature of a new(ish) standard?
- hawski 8y agoIt is guaranteed per C99. It's a compound initializer. Also if you set a struct with {1} the first field is set to 1 and the rest to 0. AFAIR it was always like that (at least since standardized C, but probably earlier).
- loeg 8y agoC99 specifies that struct literals with absent fields are assigned a zero value. (Notably unspecified is the value of any implicit padding bytes in the struct.)