[Mono-dev] Mono runtime segfault

Kornél Pál kornelpal at hotmail.com
Tue Aug 23 03:52:49 EDT 2005


The code that David created is called recursion as property accessors are
methods. Furthermore you cannot have a field and a property with the same
name so you have to declare a filed with a different name if you want to
store property value.

Recursion is coding technique that has a lot of usages. And it's difficult
to determine whether a recursion is infinite or will end at a time.
Furthermore you may want to do an endless recursion to cause stack overflow
or wait for another thread to interrupt the recursion.

Similar to infinite loops and infinite recursion are things that has to be
allowed by the compiler.

Kornél

----- Original Message -----
From: "knocte" <knocte at gmail.com>
To: <mono-devel-list at lists.ximian.com>
Sent: Tuesday, August 23, 2005 9:40 AM
Subject: Re: [Mono-dev] Mono runtime segfault


> On 8/23/05, David Carr <dc at dcarr.org> wrote:
> > I'm getting an unexpected segfault running the code below:  Forgive me
> > if its a silly mistake on my part.
> >
> > Thanks for any help,
> > David Carr
> >
> > david at Cadmium ~/Prog/c#/gcross $ mono Crash.exe
> > Segmentation fault
> >
> > Listing for Crash.cs:
> > public class Crash
> > {
> >     int var
> >     {
> >     get { return var; }
> >     set { var = value; }
> >     }
> >
> >     public Crash(int i)
> >     {
> >     var = i;
> >     }
> >
> >     public static void Main()
> >     {
> >     Crash c = new Crash(10);
> >     }
> >
> > }
> >
2005/8/23, feelite qiu <autolysis at gmail.com>:
> hi David
>
>  the code snippet
>
>     int var
>     {
>     get { return var; }
>     set { var = value; }
>     }
>
>
>  creates an infinite loop as properties are internally implemented as
> methods. So when you instantiate the object,
>
>   Crash c = new Crash(10);
>
>  This chain of action is what I understand
>
>  new Crash(10) -> var = 10; -> set { var = 10; } ->  get { return
> var; } ->
> get { return var; } ->...
>
>  the error lies in the fact that your property var does not refer to an
> underlying field. You can try
>
>  int Var;
>   int var
>     {
>     get { return Var; }
>     set { Var = value; }
>     }
>
>
>  regards
>  feelite
>
>

Interesting. Could be implemented a new option in the mono compiler to
show a warning message in this situation? Perhaps it is interesting
just to file a new Request For Enhancement in bugzilla, isn't it?

Regards,

  Andrew

--
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list




More information about the Mono-devel-list mailing list