[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
access violation
Access violation

A run-time  ?error caused by the reading/writing to an illegal memory location.

This error mostly happens when working with [[array|arrays]]. Because it is a run-time error, it is nasty to debug. Also, these errors do not happen on every occasion, as sometimes they are not detected...

An example program that might give you an access violation:

int array[10];
int * pArray = &array[0];
  • (pArray+11) = 69;


The last line essentially being the same as:
array[11]=69;


Preventing access violations

  • Prevent the use of  ?pointer arithmetic (like in the example above), use array indexing instead.
  • Prefer the use of vector over the use of an array.
  • When using a vector, use either assert or the member function at(), which first does a  ?range check for you.


last edited (July 15, 2005) by bilderbikkel, Number of views: 4488, Current Rev: 5 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.