Update to a useful feature in the Sun Studio C compiler
By dpagan on Jun 04, 2008
Regarding an earlier blog post, where I discussed a new option to the -xcheck flag, there are two new updates coming down the line (most likely in the next Sun Studio Express release). First, the [no%]init_local option to -xcheck will become a regular user option. In other words, it will no longer be necessary to use the -W0 special compiler switch to use this feature.
Second, initialization of local variables will be be extended to include local arrays, structs and unions. Initialization of these types will build on the existing initializations such that they are natural extensions of what is performed today. For example, if a local array's elements are type float, then each element will be initialized with the same value used for a simple float local variable. Likewise, for local struct variables, members that are simple types will be initialized as expected (struct members that are themselves structs, arrays or unions, will be initialized using the same methods described here). Unions, however, will be treated just a bit differently than structs or arrays. To maximize the potential that a reference to an uninitialized union will generate a visible error, they will be initialized with the appropriate value for the first declared pointer or float field. If a union contains no members of these types, then a default initialization value will be chosen.
Once again, note that the specific values used for initializations of simple types is always subject to change and can't be relied upon to remain identical between releases. Also, note that by the very nature of what -xcheck=init_local does, memory debuggers most likely will not be able to detect uses of uninitialized local variables in code compiled with this flag.
Feel free to comment about the utility of this feature directly to me or comment via SDN (Sun Developer Network - http://developers.sun.com/) C compiler forums. If you aren't a member, become one and let us know what you think about Sun Studio.