www.digitalmars.com         C & C++   DMDScript  

D - Request for feature or bug?

reply MicroWizard <MicroWizard_member pathlink.com> writes:
Request for feature or bug?

I don't find anything in the documentation about that:
Should D make any run-time check whether a reference to an object is null
or not, before it calls a member function?

I wrote the attached program and it hangs up (CTRL-C can terminate :-)
if I left out the marked line.

Obviously there is a bug in my program in this case. The reference
variable was created only and no physical object.

I think it is a typical problem for C++ programmers when starting
to use D. First I tought the object instance will be created...

This bug can be caught only before the call is made to
I_don't_know_where, the CPU does not call the member where
the catch would also be possible.

A run-time check for null (with an exception thrown if needed)
would be fine or is any other solution?

Thanks in advance,
Tamas

--------------------------
import c.stdio;

class xRecord{
int b;

this() {b=3;}
void set(int x)
{
if(this==null)
{
throw new Error("OOOooooppppsss !");
}
else
{
printf("The value of _this_: %p\n",this);
}
b=x;
}
}

void main(char[][] args)
{
xRecord xr2;
//    xr2=new xRecord();	//*********************************

printf("start\n");

if(xr2==null)
{
printf("xr2 is null\n");
}
else
{
printf("xr2 is: %p\n",xr2);
}

xr2.set(10); // hangs up if xr2 equals to null

printf("finish\n");
}
--------------------------------

Tamas Nagy
MicroWizard Ltd.
Hungary
May 05 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"MicroWizard" <MicroWizard_member pathlink.com> wrote in message
news:ab38mr$2b7d$1 digitaldaemon.com...

 Should D make any run-time check whether a reference to an object is null
 or not, before it calls a member function?
I would suggest to put it into the same category as the array bounds check. It would be too slow in release builds, but when debugging, error, instead of just "Access Violation at blablabla".
May 05 2002
next sibling parent MicroWizard <MicroWizard_member pathlink.com> writes:
In article <ab3ak8$2cqj$1 digitaldaemon.com>, Pavel Minayev says...
"MicroWizard" <MicroWizard_member pathlink.com> wrote in message
news:ab38mr$2b7d$1 digitaldaemon.com...

 Should D make any run-time check whether a reference to an object is null
 or not, before it calls a member function?
I would suggest to put it into the same category as the array bounds check. It would be too slow in release builds, but when debugging, error, instead of just "Access Violation at blablabla".
I agree completely. Tamas Nagy
May 05 2002
prev sibling next sibling parent "OddesE" <OddesE_XYZ hotmail.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:ab3ak8$2cqj$1 digitaldaemon.com...
 "MicroWizard" <MicroWizard_member pathlink.com> wrote in message
 news:ab38mr$2b7d$1 digitaldaemon.com...

 Should D make any run-time check whether a reference to an object is
null
 or not, before it calls a member function?
I would suggest to put it into the same category as the array bounds check. It would be too slow in release builds, but when debugging, error, instead of just "Access Violation at blablabla".
Agreed. -- Stijn OddesE_XYZ hotmail.com http://OddesE.cjb.net _________________________________________________ Remove _XYZ from my address when replying by mail
May 05 2002
prev sibling parent reply "Matthew Wilson" <mwilson nextgengaming.com> writes:
Is there some distinction in the compiler/libraries between debug and
release builds?

"Pavel Minayev" <evilone omen.ru> wrote in message
news:ab3ak8$2cqj$1 digitaldaemon.com...
 "MicroWizard" <MicroWizard_member pathlink.com> wrote in message
 news:ab38mr$2b7d$1 digitaldaemon.com...

 Should D make any run-time check whether a reference to an object is
null
 or not, before it calls a member function?
I would suggest to put it into the same category as the array bounds check. It would be too slow in release builds, but when debugging, error, instead of just "Access Violation at blablabla".
May 06 2002
parent "Pavel Minayev" <evilone omen.ru> writes:
"Matthew Wilson" <mwilson nextgengaming.com> wrote in message
news:ab7efd$fv9$1 digitaldaemon.com...

 Is there some distinction in the compiler/libraries between debug and
 release builds?
In release build, compiler removes all assertions, invariant calls and unittests from generated code. It also doesn't perform array bounds checks. As for the library, currently, only debug version exist (with all checks turned on), due to the alpha nature of the compiler. But I guess that, as soon as Walter is sure there are no serious bugs left in there, he'll do a recompile in release mode.
May 06 2002