Page 2 of 3

Re: Constructors not called ???

Posted: Tue May 19, 2009 8:05 am
by quanganht
fieldofcows wrote: 1) Your constructor does not seem to call clrscr() like you mentioned in your post.
2) The vram variable is set to 0x8B00. Shouldn't this be 0xB8000?

Does the screen clear correctly if you call clrscr() after your class is constructed, i.e. outside of the constructor?
I've fixed all of them but still the same. Calling clrscr() in or outside constructor will make no different.

Re: Constructors not called ???

Posted: Tue May 19, 2009 9:07 am
by quanganht
Gone unsolved ? :x
Should I fall back to C ? ( Need your suggestions ) :?:

Re: Constructors not called ???

Posted: Tue May 19, 2009 9:15 am
by Troy Martin
You have checked out the C++ Bare Bones, haven't you? I would assume all you need is in there. That and the C++ article.

Re: Constructors not called ???

Posted: Tue May 19, 2009 10:00 am
by quanganht
Troy Martin wrote:You have checked out the C++ Bare Bones, haven't you? I would assume all you need is in there. That and the C++ article.
I must scout that page before starting. I think there must be some bugs.

Re: Constructors not called ???

Posted: Tue May 19, 2009 5:20 pm
by fieldofcows
quanganht wrote:I must scout that page before starting. I think there must be some bugs.
Yes, there are a few bugs in the code. One that may be a cause of confusion is that your clrscr() function seems to actually scroll the screen up a line.

Should this code:

Code: Select all

vram[i] = vram[i+80];
be this?

Code: Select all

vram[i] = blank
I also disassembled the .o files in your archive and the constructor is definitely being called in kernel.o.

Re: Constructors not called ???

Posted: Tue May 19, 2009 5:55 pm
by quanganht
Thanks for your help but it just doesn't make any difference.

Notice in the source I attached in this post: I've added a init() fuction which acts like the constructor, then I call it. After that, the clrscr() works fine, but not for write() or put().

Re: Constructors not called ???

Posted: Tue May 19, 2009 6:21 pm
by xyjamepa
Hi,

I think you should take a look at this
hope it help.

Re: Constructors not called ???

Posted: Tue May 19, 2009 6:38 pm
by quanganht
abuashraf wrote:Hi,

I think you should take a look at this
hope it help.
Have seen it several times before. Trying but don't sure it will help. Thanks anyway

Re: Constructors not called ???

Posted: Tue May 19, 2009 6:56 pm
by pcmattman
Notice in the source I attached in this post: I've added a init() fuction which acts like the constructor, then I call it. After that, the clrscr() works fine, but not for write() or put().
You're on the right track now. You must test your console functions before you try to put them in a class. Otherwise you've got no idea whether or not they actually work!

Re: Constructors not called ???

Posted: Wed May 20, 2009 1:28 am
by Solar
Ok. /me confused. And when I'm confused, I take a step back and summarize.

1) You do not need any support code, standard library or otherwise, to have member object constructors called.

2) You do need support code in your loader assembly to have the constructors of any global objects called. I would guess this is also true for static member objects, but I haven't checked that. Bare Bones C++ and other sources show how to do this.

3) You do need support code to use "new".

4) You must check any functionality "outside the box" before you use it as an indicator for saying other things don't work. (Printing a character, clearing the screen etc.)

With all due respect, but I think those 4 points should solve quanganht's problem...

Re: Constructors not called ???

Posted: Wed May 20, 2009 6:57 am
by quanganht
After quite a while strugling, the code suddenly worked!( although '\n' did perormed right )
And I don't even understand what happened. I guess there is bugs inside put(), because when I rewrite it, "Hello world!" can be seen.

If anyone can find what's wrong with '\n', thanks!

Re: Constructors not called ???

Posted: Wed May 20, 2009 2:39 pm
by cyr1x
Constructors are always called when an object is created on the stack.
For global objects you need to call the constructor yourself
either you use the way JamesM pointed out or you do

Code: Select all

CConsole console;
void kmain() { console.CConsole(); }

Re: Constructors not called ???

Posted: Wed May 20, 2009 6:07 pm
by quanganht
cyr1x wrote:Constructors are always called when an object is created on the stack.
For global objects you need to call the constructor yourself
either you use the way JamesM pointed out or you do

Code: Select all

CConsole console;
void kmain() { console.CConsole(); }
Thats not a good idea as we already have a way to call all the global objects' constructors at start up.

Re: Constructors not called ???

Posted: Thu May 21, 2009 12:01 am
by cyr1x
I never said that this was a good idea, I only said that it's possibly to do it that way.

Re: Constructors not called ???

Posted: Thu May 21, 2009 5:38 am
by xyjamepa
Hi,

maybe this is useful.

Good luck