This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/ARM-CGT: Feature request: compiler warnings around designated initializer usage

Expert 1226 points
Part Number: ARM-CGT


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

  • I feel less comfortable than usual with this request.  Static code analysis such as this is not a point of focus with TI, even though our tools have integrated a few such features.  However, static code analysis is very much a point of focus for several other software tool vendors.  I am certain you would be much happier working with one of those vendors for a solution to this problem.

    All that said, I filed the entry EXT_EP-9797 to have your suggestion considered.  It is not filed as a bug, but as a request for a change in the compiler.  You are welcome to follow it with the link below in my signature.

    Thanks and regards,

    -George

  • George Mock said:
    I filed the entry EXT_EP-9797 to have your suggestion considered.

    Unfortunately, this request is declined.  It is judged that too few customers would benefit.  Further, we prefer to focus our efforts on making compiled code faster, smaller, and more power efficient.  Spending effort on static checks takes away from that focus.

    Thanks and regards,

    -George