4 ms·
Designated initializers are very important. As a maintainer of a codebase that has to support older Windows OSes and MSVC releases, I still suffer from not bei
by cryptonector 7y ago
Designated initializers are very important. As a maintainer of a codebase that has to support older Windows OSes and MSVC releases, I still suffer from not being able to use them.
Really, GP is correct, MSFT did immense harm by not implementing more/all of C99 sooner. I'm still quite annoyed by that even now, even now that MSFT has finally started doing amazing things.
- kazinator 7y ago> Designated initializers are very important. I use macros or functions to initialize structures. When a new member is added that must be initialized to a non-default value, I can add a parameter to the intializer, and then the compiler finds all the places where an argument must be added. I could easily work this gradually into an old code base that I have to maintain. Such an initializer macro can be implemented itself using designated initializers, but that is of low value; it's in one place, next to where the struct is declared. The designated initializer clearly wins if we have to declare a large, sparse array without executing code, and initialize just a few entries to nonzero which are not close to the beginning.
- cryptonector 7y agoIf you're using cscope/etags/an IDE then you want the field name to be visible where the assignment is made, otherwise finding your way around a codebase with many function dispatch tables can get painful.
- kazinator 7y agoI have a macro or function name that occurs wherever the struct is initialized. struct point p = point_init(x, y); ctags will find the definition of point_init, and cscope all the occurrences. Random code throughout the program that is not related to the data type's module shouldn't be performing explicit low-level member-for-member initializations of the data type, even with a safer mechanism like designated initializers.
- cryptonector 7y agoYes, but if you have a struct with many functions then you still have a problem. With designated initializers I can traverse all the paths through cscope alone.
- kazinator 7y agoI can't even begin to imagine a foggy gist of what you might be talking about, but it seems very real to you.
- cryptonector 7y agoI should do an asciicinema thing, I guess. Point is, I can search for assignments to any one function-typed fieldname of a struct and find all the functions that are reachable through instances of that struct.
- kazinator 7y agoAre we (still) talking about C here? Initialization isn't assignment in C; structure elements are called "members" and they cannot be functions.