0

Possible Duplicate:
C++ Accesses an Array out of bounds gives no error, why?

I have a recurring problem with array using Qt creator on Windows. When my program tries to access a memory cell that doesn't exist there are randomiz crashes so it is very difficult to debug.

Is there any library or option to check in order to stop the program when my program accesses a non existing memory cell?

Example:

int * toto = new int [4];
toto[6] =2;

Leads to mentioned random behavior.

I'm on Windows 7 using Qt creator 4.8.1.

Community
  • 1
  • 1
matthieu
  • 1
  • 3

1 Answers1

0

As @axeoth mentioned in comment there is no way to check whether index is out of range for C++ array.

If you are looking for Qt-specific container classes you can take a look at QList<T> or QVector<T>.

You can find more details at Qt Container Classes.

Alexander Stepaniuk
  • 6,217
  • 4
  • 31
  • 48
  • thank you very much for your answers and your links guys. to conclude C++ array have very fast access but there is no way to debug it easily. – matthieu Jan 04 '13 at 15:42
  • Access spee is the same for std::vector and arrays. See e.g. http://stackoverflow.com/questions/381621/using-arrays-or-stdvectors-in-c-whats-the-performance-gap Assuming otherwise without measuring is sort of premature non-optimization... ;) – Frank Osterfeld Jan 04 '13 at 16:59