www.digitalmars.com         C & C++   DMDScript  

D - Dernel: dynamic arrays

reply =?iso-8859-1?Q?=22Robert_M._M=FCnch=22?= <robert.muench robertmuench.de> writes:
Hi, I have the following code, that makes some problems.

This works:
	char[] str1 = "abc";
	k_println(str1);

And this part fails:
	Object obj1;

	char[] str1;
	str1 = obj1.toString();
	k_println(str1);

What's happening at the line with the assignment? The code compiles 
without any unresoleved reference errors but bombs. This is the ASM 
output, of the second code snippet.

		push	EBP
		mov	EBP,ESP
		xor	EAX,EAX
		mov	ECX,[EAX]
		call	dword ptr 8[ECX]
		push	EDX
		push	EAX
		call	near ptr _D6kernel7console7printlnFAaZv
		pop	EBP
		ret

What is this "call dword ptr 8[ECX]" thing? Is this a call thru the vtable 
of the object? It seems, that my stack pointer is wrong. But I don't do 
anything with it. Maybe that's the problem...

-- 
Robert M. Münch
Management & IT Freelancer
http://www.robertmuench.de
Feb 19 2004
parent reply "davepermen" <davepermen hotmail.com> writes:
your object is a null reference.. or have you obj = new Obj; somewhere?
"Robert M. Münch" <robert.muench robertmuench.de> schrieb im Newsbeitrag
news:opr3lzklwium5vd8 news.digitalmars.com...
 Hi, I have the following code, that makes some problems.

 This works:
 char[] str1 = "abc";
 k_println(str1);

 And this part fails:
 Object obj1;

 char[] str1;
 str1 = obj1.toString();
 k_println(str1);

 What's happening at the line with the assignment? The code compiles
 without any unresoleved reference errors but bombs. This is the ASM
 output, of the second code snippet.

 push EBP
 mov EBP,ESP
 xor EAX,EAX
 mov ECX,[EAX]
 call dword ptr 8[ECX]
 push EDX
 push EAX
 call near ptr _D6kernel7console7printlnFAaZv
 pop EBP
 ret

 What is this "call dword ptr 8[ECX]" thing? Is this a call thru the vtable
 of the object? It seems, that my stack pointer is wrong. But I don't do
 anything with it. Maybe that's the problem...

 -- 
 Robert M. Münch
 Management & IT Freelancer
 http://www.robertmuench.de
Feb 19 2004
parent reply "=?iso-8859-1?Q?Robert_M._M=FCnch?=" <robert.muench robertmuench.de> writes:
On Thu, 19 Feb 2004 15:32:38 +0100, davepermen <davepermen hotmail.com>  
wrote:

 your object is a null reference.. or have you obj = new Obj; somewhere?
Hi, no, because it's a (local) stack object. Or is this not supported? IIRC this is totaly legal. Robert -- Robert M. Münch Management & IT Freelancer http://www.robertmuench.de
Feb 20 2004
parent "Walter" <newshound digitalmars.com> writes:
"Robert M. Münch" <robert.muench robertmuench.de> wrote in message
news:opr3n2w8yoheztw6 news.digitalmars.com...
 On Thu, 19 Feb 2004 15:32:38 +0100, davepermen <davepermen hotmail.com>
 wrote:

 your object is a null reference.. or have you obj = new Obj; somewhere?
Hi, no, because it's a (local) stack object. Or is this not supported? IIRC this is totaly legal. Robert
Class objects are not on the stack; you'll need to new them.
Jun 23 2004