Re: Test for an initialised object

David Hakim <dhakim-Gkm/TONP9n1Wk0Htik3J/[email protected]> Tue, 6 May 2003 18:27:53 -0400
Newsgroups gmane.comp.lang.moto.devel
Message-ID <[email protected]>
re: Could we add an "initialised" field to the MotoVal struct, and set 
it in motov_new?

Well, all variables in moto are given an initial value at declaration 
time. For objects this default value is just null (for numerics and 
other atomic types its 0).

Also, variables cannot be used without being declared. If a programmer 
tries to use a variable without declaring it first motov will report an 
error.

So moto really does not allow variable use prior to inilialization as 
such.

Did you want to add this field so motov could report a warning to 
programmers that they 'might' be using a variable that they did not yet 
assign a value to ?

-Dave


On Tuesday, May 6, 2003, at 10:05  AM, Stefano Corsi wrote:

> Dave,
>
> there is no method, as far as I see, to test in motov if an object has 
> been
> initialised. So the only way I found, inside motox, to test for a 
> method call
> on a null object is this:
>
>     /* If this is not an object... */
>     if (v1->type->kind != REF_TYPE) {
>         /* Nothing to do */
>         return FTAB_NONE;
>     }
>
>     /* Test for a null object */
>     if (mode == MODE_MOTOI || mode == MODE_MOTOC) {
>         if (v1->refval.value == NULL) {
>             THROW("NullPointerException",
>                 "A method overloaded operator may not be identified on 
> null");
>         }
>     }
>
> i.e throwing an exception in motoi and motoc.
> Could we add an "initialised" field to the MotoVal struct, and set it 
> in
> motov_new?
>
> Stefano
>