- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[cpp]
void foo(int a) {
while(a);
}
int main() {
foo(1);
}[/cpp]
Compiler removes empty loop and there is no endless loop that i expect. MSVC and GCC works correctly.
Windows, ICC 13.1.
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With Intel C++ compiler this is a well know issue but it is Not a problem. What optimization options did you use, /O1, /O2 or /O3?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With any level of optimization.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>...Compiler removes empty loop and there is no endless loop that i expect...
Do you need to use a similar processing in a real application?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Adding "#pragma intel optimization_level 0" before the function "foo()" will keep the loop.
Or introduce a volatile variable like below:
//#pragma intel optimization_level 0
void foo(int a) {
volatile int b=a;
while(a)
;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Okay, i forgot about volatile, thanks.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page