Constructors not called ???

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Constructors not called ???

Post 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.
"Programmers are tools for converting caffeine into code."
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Constructors not called ???

Post by quanganht »

Gone unsolved ? :x
Should I fall back to C ? ( Need your suggestions ) :?:
"Programmers are tools for converting caffeine into code."
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: Constructors not called ???

Post 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.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Constructors not called ???

Post 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.
"Programmers are tools for converting caffeine into code."
fieldofcows
Posts: 4
Joined: Tue Dec 09, 2008 5:34 pm

Re: Constructors not called ???

Post 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.
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Constructors not called ???

Post 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().
Attachments
src.rar
(5.34 KiB) Downloaded 38 times
"Programmers are tools for converting caffeine into code."
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Re: Constructors not called ???

Post by xyjamepa »

Hi,

I think you should take a look at this
hope it help.
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Constructors not called ???

Post 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
"Programmers are tools for converting caffeine into code."
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: Constructors not called ???

Post 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!
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Constructors not called ???

Post 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...
Every good solution is obvious once you've found it.
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Constructors not called ???

Post 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!
Attachments
src.rar
(5.51 KiB) Downloaded 62 times
"Programmers are tools for converting caffeine into code."
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Re: Constructors not called ???

Post 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(); }
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Constructors not called ???

Post 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.
"Programmers are tools for converting caffeine into code."
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Re: Constructors not called ???

Post by cyr1x »

I never said that this was a good idea, I only said that it's possibly to do it that way.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Re: Constructors not called ???

Post by xyjamepa »

Hi,

maybe this is useful.

Good luck
The man who follows the crowd will usually get no further than the crowd.
The man who walks alone is likely to find himself in places
no one has ever been before.
Post Reply