在C/C++程序中,全局和静态变量,编译器会默认初始化为0。而局部变量是没有默认值的,分配到的内存空间保留原有无意义的值。
在很多老旧代码中,初始化和使用都不规范,导致非常容易出现异常情况。
为了降低异常的概率,通过xlc的编译参数,可以让局部变量也进行默认值初始化动作。
参考xlc的帮助:
-qinitauto=<hex_value> | -qnoinitauto
Initializes each byte or word of storage for
automatic variables to the specified hexadecimal
value <hex_value>. This generates extra code and
should only be used for error determination.
于是,只要在编译选项中增加-qinitauto=00,即可。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/283313/viewspace-2138941/ ,如需转载,请注明出处,否则将追究法律责任。