dimanche 15 mars 2015

Why does g++ not throw out of range for variable length arrays


I have a piece of code like so:



int arr[n];
int i, j, x, y;

for(y = 0; y < n; y++)
for(x = 0; x < n; x++)
// do stuff
// x = y = n
std::cout << arr[x][y];


the code is part of an implementation of A* and more surprisingly it works great, but I noticed i'm actually accessing an out of bounds element in my array. Why does g++ allow me to do this without any sort of exception being thrown?




Aucun commentaire:

Enregistrer un commentaire