www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Access voilation ?

reply Sai <Sai_member pathlink.com> writes:
Can any one please tell me what exactly causes 
"Access Voilation" runtime error ?

I am haunted by it all the times.


is it difficult to get call stack trace in D when an app crashes ? 

I am sorry I have no clue of how compilers work.

Thanks
Sai
Sep 05 2004
next sibling parent "antiAlias" <fu bar.com> writes:
The most frequent reason for this is mistaken usage of printf(). If you're
trying to use a char[] with printf(), you must use the "%.*s" format rather
than "%s". Alternatively, use writef() instead.

Second most frequent error seems to be using a class 'instance' without
assigning it. For example:

Class X {void foo(){}}

void main()
{
   X x;

   x.foo();  // access violation

   x = new X;
   x.foo();  // correct
}

Other, more esoteric, reasons relate to static constructors.

Good luck;


"Sai" <Sai_member pathlink.com> wrote in message
news:chffpa$esi$1 digitaldaemon.com...
Can any one please tell me what exactly causes
"Access Voilation" runtime error ?

I am haunted by it all the times.


is it difficult to get call stack trace in D when an app crashes ?

I am sorry I have no clue of how compilers work.

Thanks
Sai
Sep 05 2004
prev sibling next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
if you're looking for a techincal description, it's caused when a program
attempts to access memory that it's not allowed to.  hence, a "violation."
back in the old days, there was real mode, where any program could affect
any other part of memory.  this was bad.  programs could very easily crash
the entire computer just by writing some stupid values to the right place in
memory.  also if a program went astray and got stuck in an endless loop of
writing stuff to memory, it could also crash the entire computer.  so they
invented protected mode, where each program is only allowed to touch certain
parts of memory, and if it tries to touch other things, it gets scolded.

probably 90% of the time MAVs are caused by "off-by-one" errors - that is,
you write past the end of an array by just one element.  D has array bounds
checking in debug mode, so at least it's a little more descriptive than
"memory access violation".  another big cause is trying to use a dead
(deleted) pointer, or when dealing with COM.  oh how i hate COM.
Sep 06 2004
parent Sai <Sai_member pathlink.com> writes:
Thanks to antiAlias and Jarrett, that was very informative. I was
not using debug mode at all (may be overconfidence ;), 
debug mode caught almost all the bugs.

Sai


In article <chhumd$1eom$1 digitaldaemon.com>, Jarrett Billingsley says...
if you're looking for a techincal description, it's caused when a program
attempts to access memory that it's not allowed to.  hence, a "violation."
back in the old days, there was real mode, where any program could affect
any other part of memory.  this was bad.  programs could very easily crash
the entire computer just by writing some stupid values to the right place in
memory.  also if a program went astray and got stuck in an endless loop of
writing stuff to memory, it could also crash the entire computer.  so they
invented protected mode, where each program is only allowed to touch certain
parts of memory, and if it tries to touch other things, it gets scolded.

probably 90% of the time MAVs are caused by "off-by-one" errors - that is,
you write past the end of an array by just one element.  D has array bounds
checking in debug mode, so at least it's a little more descriptive than
"memory access violation".  another big cause is trying to use a dead
(deleted) pointer, or when dealing with COM.  oh how i hate COM.
Sep 08 2004
prev sibling parent J C Calvarese <jcc7 cox.net> writes:
Sai wrote:
 Can any one please tell me what exactly causes 
 "Access Voilation" runtime error ?
Various problems can lead to "Access Violations". Here's some of the common ones: http://www.prowiki.org/wiki4d/wiki.cgi?ErrorMessages#RuntimeErrors
 
 I am haunted by it all the times.
 

 is it difficult to get call stack trace in D when an app crashes ? 
 
 I am sorry I have no clue of how compilers work.
 
 Thanks
 Sai
 
 
-- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Sep 06 2004