- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am testing with code that cannot check the previous execution environment.
And in optimization flag O2, I found that uninitialized variables are initialized to inconsistent values each time I try to run.
Is there a way to get the Intel compiler to initialize uninitialized variables to a specific value?
(Any compiler options?)
And how does the value of uninitialized variables change depending on the setting of the optimization flags(O0 or O2) in the Intel compiler?
Thanks.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
Thank you for reaching out.
>Is there a way to get the Intel compiler to initialize uninitialized variables to a specific value?
There are various ways to catch hold of uninitialized variables in the code. Some of them are listed below:
- By specifying keyword uninit for option check.
Ex: icpc -check=uninit test.cpp
- By using -ftrapuv(/Qftrapuv in case of windows) which initializes stack local variables to an unusual value to aid error detection
Ex: icpc -ftrapuv test.cpp
- In Windows, By using /0d /RTC1 which initializes all local variables to a non-zero value.
>how does the value of uninitialized variables change depending on the setting of the optimization flags(O0 or O2) in the Intel compile?
We will discuss this with the internal team and get back to you
Thanks and Regards
Gopika
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I work with Linux, so using '-check=uninit' would be very helpful.
Thank you and I'll look forward to your response to my second question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can also use -Wuninitialized flag to get a warning if a variable is used before being initialized.
C/C++ does not automatically initialize variables to a given value. So when the compiler assigns a memory location to a variable,
the default value of that variable is whatever value happens to be in that memory location, often is a garbage.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Viet_H_Intel - After your explanation, I got a better understanding of the variables initialization in C compiler.
Thank you for your answer.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>how does the value of uninitialized variables change depending on the setting of the optimization flags(O0 or O2) in the Intel compile?
Generated code between O0 vs.O2 will be different, so memory assigns for that variable won't be the same location between to cases, so its value is just whatever happens to be in that location.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Let us know if this is still an issue. Otherwise, we will close it.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We will no longer respond to this thread.
If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only.
Thank,

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page