This program prints 0, when it, clearly, should print 11.
#include <stdio.h> struct S0 { int t = 11; }; struct S2 : virtual S0 { }; S2 g_1[1]; int main(int argc, char* argv[]) { printf("%d", g_1[0].t); }
This code compiled with the follow command on windows:
iclvars.bat intel64 & icl file.cpp /w /link /out:file.exe
Version:
Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.3.207 Build 20160415
Link Copied
Have you gotten this error when compiling the above code?
file.cpp(5): error: data member initializer is not allowed
int t = 11;
^
Thanks,
Viet
Hello,
In this version (Intel(R) 64, Version 16.0.3.207 Build 20160415) this code compiled without an error.
the problem was that the program printed "0" instead of "11".
Regards,
Tamir Aviv.
Viet this program uses field initializers which is a C++11 feature only available if your reference compiler is MSVC++ 2013 or later or if you use the /Qstd=c++11 or /Qvc12 or /Qvc14 options.
Anyway I can reproduce the problem with 16.0 but it is fixed in 17.0 so please upgrade to get the fix for this... Sorry for the inconvenience.
Judy
For more complete information about compiler optimizations, see our Optimization Notice.