www.digitalmars.com         C & C++   DMDScript  

D - Access violation

reply Patrick Down <pat codemoon.com> writes:
I think this is another nested function
issue.  When the array is accessed in the if 
statement the program bombs.


struct Foo
{
  int[] arr;
}

void Func(Foo bar)
{
    void InnerFunc(int x, int y)
    {
      int a = bar.arr[y]; // Ok
    
      if(bar.arr[y]) // Access violation
      {
      }
    }
    
    InnerFunc(5,5);
}


int main(char[][] argv)
{
  Foo bar;

  bar.arr.length = 10;

  Func(bar);

  return 0;
}
Aug 21 2003
next sibling parent reply "Walter" <walter digitalmars.com> writes:
Try:
    Foo bar = new Foo();

"Patrick Down" <pat codemoon.com> wrote in message
news:Xns93DEDC71D4F74patcodemooncom 63.105.9.61...
 I think this is another nested function
 issue.  When the array is accessed in the if
 statement the program bombs.


 struct Foo
 {
   int[] arr;
 }

 void Func(Foo bar)
 {
     void InnerFunc(int x, int y)
     {
       int a = bar.arr[y]; // Ok

       if(bar.arr[y]) // Access violation
       {
       }
     }

     InnerFunc(5,5);
 }


 int main(char[][] argv)
 {
   Foo bar;

   bar.arr.length = 10;

   Func(bar);

   return 0;
 }

Aug 23 2003
parent reply Patrick Down <pat codemoon.com> writes:
"Walter" <walter digitalmars.com> wrote in news:bi8is8$4h8$1
 digitaldaemon.com:

 Try:
     Foo bar = new Foo();

Foo is a struct why does it need a new?
 
 "Patrick Down" <pat codemoon.com> wrote in message
 news:Xns93DEDC71D4F74patcodemooncom 63.105.9.61...
 I think this is another nested function
 issue.  When the array is accessed in the if
 statement the program bombs.


 struct Foo
 {
   int[] arr;
 }

 void Func(Foo bar)
 {
     void InnerFunc(int x, int y)
     {
       int a = bar.arr[y]; // Ok

       if(bar.arr[y]) // Access violation
       {
       }
     }

     InnerFunc(5,5);
 }


 int main(char[][] argv)
 {
   Foo bar;

   bar.arr.length = 10;

   Func(bar);

   return 0;
 }


Aug 23 2003
parent "Walter" <walter digitalmars.com> writes:
Sorry, you're right.

"Patrick Down" <pat codemoon.com> wrote in message
news:Xns93E0A875E661Epatcodemooncom 63.105.9.61...
 "Walter" <walter digitalmars.com> wrote in news:bi8is8$4h8$1
  digitaldaemon.com:

 Try:
     Foo bar = new Foo();

Foo is a struct why does it need a new?
 "Patrick Down" <pat codemoon.com> wrote in message
 news:Xns93DEDC71D4F74patcodemooncom 63.105.9.61...
 I think this is another nested function
 issue.  When the array is accessed in the if
 statement the program bombs.


 struct Foo
 {
   int[] arr;
 }

 void Func(Foo bar)
 {
     void InnerFunc(int x, int y)
     {
       int a = bar.arr[y]; // Ok

       if(bar.arr[y]) // Access violation
       {
       }
     }

     InnerFunc(5,5);
 }


 int main(char[][] argv)
 {
   Foo bar;

   bar.arr.length = 10;

   Func(bar);

   return 0;
 }



Aug 23 2003
prev sibling parent "Walter" <walter digitalmars.com> writes:
You're right, it's a nasty bug. I have it fixed now, fix will go out in
0.71. Thanks, -Walter
Aug 25 2003