Thread overview
Access violation
Aug 22, 2003
Patrick Down
Aug 23, 2003
Walter
Aug 23, 2003
Patrick Down
Aug 24, 2003
Walter
Aug 25, 2003
Walter
August 22, 2003
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;
}
August 23, 2003
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;
> }


August 23, 2003
"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;
>> }
> 
> 

August 24, 2003
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;
> >> }
> >
> >
>


August 25, 2003
You're right, it's a nasty bug. I have it fixed now, fix will go out in 0.71. Thanks, -Walter