www.digitalmars.com         C & C++   DMDScript  

D - Strange Problem with class

reply "Robert M. Münch" <robert.muench robertmuench.de> writes:
Hi, I have the following code that will get my CPU usage to 100% and never
terminates:

import stdio;

class bo_template {
int name = 1;
}

int main ()
{
bo_template bo_test;
printf("%d\n", bo_test.name);
return 0;
}


Any idea, what the problem is?

--
Robert M. Münch
IT & Management Freelancer
Mobile: +49 (0)177 2452 802
Fax   : +49 (0)721 8408 9112
Web   : http://www.robertmuench.de
Sep 22 2002
next sibling parent reply Patrick Down <pat codemoon.com> writes:
"Robert M. Münch" <robert.muench robertmuench.de> wrote in
news:amkm3c$1vdh$1 digitaldaemon.com: 

 Hi, I have the following code that will get my CPU usage to 100% and
 never terminates:
 
 import stdio;
 
 class bo_template {
 int name = 1;
 }
 
 int main ()
 {
 bo_template bo_test;
 printf("%d\n", bo_test.name);
 return 0;
 }
 
 
 Any idea, what the problem is?
Yes, bo_test is not initialized. You need... bo_test = new bp_template(); It seems that in the Windows version of DMD a null object reference seems to go off into la la land.
Sep 22 2002
parent "Robert M. Münch" <robert.muench robertmuench.de> writes:
"Patrick Down" <pat codemoon.com> schrieb im Newsbeitrag
news:Xns92917C401B5E1patcodemooncom 63.105.9.61...

 Yes, bo_test is not initialized.
 You need...

 bo_test = new bp_template();
Hi, :-| mea culpa. Of course this should be done. I'm programming with to much scripting languages where you just mention objects an get them.
 It seems that in the Windows version of
 DMD a null object reference seems to go
 off into la la land.
Yes, that's the case. It should give a runtime error because of 0-object reference usage. Robert
Sep 24 2002
prev sibling parent Burton Radons <loth users.sourceforge.net> writes:
Robert M. Münch wrote:
 Hi, I have the following code that will get my CPU usage to 100% and never
 terminates:
 
 import stdio;
 
 class bo_template {
 int name = 1;
 }
 
 int main ()
 {
 bo_template bo_test;
 printf("%d\n", bo_test.name);
 return 0;
 }
bo_test is pointing to null here.
Sep 22 2002