- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It seems that I've found a bug in the Intel C++ Compiler (2013.1.117, 2013.0.079, didn't try older versions) on 64-bit Linux. The following code prints random garbage instead of a constant (1234) if compiled with any kind of optimization:
[cpp]
// Compile: icpc volatilebug.cpp
#include <stdio.h>
struct Vec
{
int x;
int y;
Vec() {}
explicit Vec(int x) : x(x), y(x) {}
};
struct P
{
void init(const Vec& v)
{
va = v;
vb = v;
c = vb.x; // no error with: c = va.x
}
Vec va;
Vec vb;
int c;
};
struct Q
{
void init(const P& k)
{
p = k;
w = 7777;
printf("%d", p.vb.x); // prints garbage instead of 1234!
}
P p;
volatile int w; // no error without volatile!
};
int main()
{
P p;
p.init(Vec(1234));
Q q;
q.init(p);
return 0;
}
[/cpp]
If I remove the volatile, p.vb.x will contain the correct value. It's also fine if I compile it without optimization or with GCC. Could anyone confirm this problem? Did I miss something or is it really a bug in the optimizer? Thanks!
Regards,
Attila
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The bug also appears with version 2011.9.300 on Windows for both 32-bit and 64-bit compilations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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