Em qui., 6 de jul. de 2023 às 16:06, Gurjeet Singh <gurjeet@singh.im> escreveu:
On Thu, Jul 6, 2023 at 8:01 AM Karina Litskevich <litskevichkarina@gmail.com> wrote: > > >> EB_SMGR and EB_REL are macros for making new structs. >> IMO these are buggy, once make new structs without initializing all fields. >> Attached a patch to fix this and make more clear when rel or smgr is NULL. > > > As long as a structure is initialized, its fields that are not present in > initialization are initialized to zeros and NULLs depending on their types. > See C99 Standard 6.7.8.21 and 6.7.8.10. This behaviour is quite well known, > so I don't think this place is buggy. Anyway, if someone else says the code > is more readable with these fields initialized explicitly, then go on.
Even though I am not a fan of the Designated Initializers feature, I agree with Karina. Per the standard, the unmentioned fields get initialized to zeroes/NULLs, so the explicit initialization to zero/null that this additional patch does is unnecessary. Moreover, I feel that it makes the code less pleasant to read.
C99, 6.7.8.21: > If there are fewer initializers in a brace-enclosed list than there are > elements or members of an aggregate, or fewer characters in a string literal > used to initialize an array of known size than there are elements in the array, > the remainder of the aggregate shall be initialized implicitly the same as > objects that have static storage duration.
C99, 6.7.8.10: > If an object that has automatic storage duration is not initialized explicitly, > its value is indeterminate.
The key points are here.
The object is not static storage duration.
The object is struct with "automatic storage duration".