Tool/software: TI C/C++ Compiler
Hello,
We use C99 designated initializers in our C code development.
We believe that, for the most part, using designated initializers improves our code, but there can be some tricky aspects about using them. It would be valuable to us, and I believe valuable to others as well, if the TI compilers were able to warn about certain potentially-erroneous usages, and I'd like to propose some possibilities for your consideration.
The first is for catching incomplete initialization. An example usage is that we commonly use a combination of an array and an enumeration, where we use the enumerations to index into the array during use and also when initializing the array. Designated initializers using the the enumerations helps with the clarity and maintainability of the code, but it is possible to accidentally leave out one of the initializers and not realize that the array's initialization has been incompletely specified.
A similar situation can occur with initialization of structures, where it is possible to intend to have every structure element of a variable be explicitly initialized, but not realize that one or more sub-object has not been initialized.
The second is for catching initializer overrides. In our own code, it is unusual for us to deliberately specify the same sub-object twice when initializing a variable. Knowing that the compiler would warn us if we were to do this would definitely be a benefit.
I appreciate that there are tricky aspects to issuing warnings about valid C code, particularly since some usages of using partial initializers are deliberate and common. I have more detailed thoughts about the subject that I'd be happy to discuss if there is interest on TI's part on continuing the discussion.
As an aside, I'll note that there have been issues in the past, and at least one minor issue still outstanding, with how TI compilers handle partial initializers whose workarounds would have benefited from having such warnings.
Thanks for your consideration!
--thx