GCC is not generating the object for part of the C++ source when an uninitialized local variable is used within an "if" block or used in another "if" statement however when the variable is initialized at the begining, GCC start generating the object correctly. This is happening only when the code is compiled with optimization level 3 (-O3).
main()
{
char apc;
WorkAreaCIUMC* workAreaCIUMC ;
/*Object code for the following "if" statement and subsequent "if" block is NOT generated by GCC due to local variable 'apc' uninitialized. */
/*Object code for the following source is generated by GCC */
long long tempAmt = 0LL;
long long calAmt = 0LL;
const char chargeCCSGOPEN[] = "PGLME";
const char ssp[] = "TSCPEVCSP";
---
-----------
-----------
/*Object code for the following "if" statement and subsequent "if" block is NOT generated by GCC due to local variable 'apc' uninitialized. */
I can fix this by initializing the 'apc' variable at the begining of the program but the problem here is we are migrating more than 2000 C++ source files to GCC and its difficult to find out where else this problem exists. I am looking for a C++ compiler option which generates the object code irrespetive of whether the local variable is initialized or not when compiled with O3.
Any pointers will be greatly appreciated. Thank you!
We are getting the difference in testing results between "As-is" (z/OS) and "To-be" (Linux) systems. It need to be fixed on new system based on GCC-Linux.
jsmith is correct. You cannot expect compilers to behave the same way when it comes to undefined behavior. The behavior is -- by definition -- undefined. The compiler could start taunting you in a fake French accent when it hit that code -- and it would be within its rights to do so.
Everyone who has ever ported code from one platform to another has run into this. The *only* solution is to fix the code. Don't blame the compiler because the code is wrong.
BTW, it is unlikely that the problem is because apc is uninitialized. The problem is almost certainly because workAreaCIUMC is not initialized.