Следующий код C или С++ должен иметь в качестве вывода "11,11,11", однако с помощью Visual Studio Professional 2013 (версия 12.0.40629.00 Обновление 5) вывод "11,0,0"! Это происходит только в сборке релиза и исчезает, когда оптимизация отключена. Является ли это ошибкой компилятора?
#include <stdio.h>
int main(void)
{
int A[100] = { 0 };
int row = 0; // BUG disappears if we make this const or short or char...
int ncols = 3; // BUG disappears if we make this const or short or char...
for (int y = row; y <= row; ++y)
{
for (int x = 0; x < ncols; ++x)
{
const int index = y * ncols + x;
//A[index] = 11; // (no bug !)
*(A + index) = 11; // BUG!!!
//*(A + y*ncols+x) = 11; // (no bug !)
//*(A + (y*ncols+x)) = 11; // BUG!!!
}
}
for (int x = 0; x < ncols; ++x)
{
printf("%d,", A[x]);
}
return 0;
}