Page 1 of 3
problem in printf stuff
Posted: Sun Nov 10, 2002 9:30 pm
by adeelmahmood1
[attachment deleted by admin]
Re:problem in printf stuff
Posted: Sun Nov 10, 2002 9:30 pm
by adeelmahmood1
[attachment deleted by admin]
Re:problem in printf stuff
Posted: Mon Nov 11, 2002 1:14 am
by Schol-R-LEA
It would help if you could give more details about your setup, i.e., what compiler you are using, whther you are in protected mode or not, etc.
Anyway, the problem that is probably doing it is that you have made the classic mistake of confusing an array base with an array pointer. When you use the an array base without a subscript, it returns the value of the first character in the array,
not a pointer to the array. Given the declaration of aprintf() in astdio.h, the appropriate arguments in the call from c_main() would be:
BTW, it is a really bad practice in C to put actual functions in a header file[sup]1[/sup]; because they are direct textual insertions into the code, this could result in the same function getting compiled more than once. The purpose of headers is to allow separately compiled coe to share certain declarations which they need for external references in linking. Thus, they should only contain function prototypes, extern variable declarations, macro definitions and constants. Furthermore, they usually have an #ifdef/#endif around them based on some unique constant declaration, to prevent them from being inserted into the same file twice. Just a bit of advice.
1) There are times in C++ when it's OK, but then only for very short, inline methods as part of a class. Such functions should be about three lines at most, and usually are nothing more than a way of securely getting or setting an instance variable.
Re:problem in printf stuff
Posted: Mon Nov 11, 2002 10:26 am
by adeelmahmood1
ok i will try what u have told me to do .. lets see how it works .. but u said
it is a really bad practice in C to put actual functions in a header file
what do u mean by that .. that i should not put the printf function in the header file?? thats what i understood from it ..actually i was going on this way i have seen many other people doing the same thing ..and also i think the real printf is in the stdio.h
can u explain this plz
thanx
Re:problem in printf stuff
Posted: Mon Nov 11, 2002 10:53 am
by Whatever5k
The header files (*.h) are meant for holding definitions and *prototypes* of functions - but they shouldn't hold the function itself. A stdio.h file only contains s.th. like this:
Code: Select all
#ifndef _INCLUDE_STDIO_H_
#define _INCLUDE_STDIO_H_
#define MAX_BUF 1024 /* something */
/* prototypes of functions */
void printf(char *, ...);
void putc(int );
...
...
But the actual printf() and putc() function are hold in .c files.
Re:problem in printf stuff
Posted: Mon Nov 11, 2002 11:36 am
by adeelmahmood1
well its still not working .. and about the environment i m using windows gcc , ld , objcopy , partcopy ...
and yes i m doing this after switching to Pmode .. well coz of Pmode this C compiled code is working so Pmode at this time is quite understood i guess
and the strange thing is that whatever i do it just prints
>>!
on top left .. even though i tried to write on some other area it still write this
>>!
at top left and just reboots
i dont know wats wrong with it
plz help me with this
Re:problem in printf stuff
Posted: Mon Nov 11, 2002 12:12 pm
by Tom
Try including my fstdio.h and try using my kprintf ( you'll need the whole file for just testing, later you can pick out the functions )
Re:problem in printf stuff
Posted: Mon Nov 11, 2002 1:31 pm
by adeelmahmood1
well ill do that now but could u also plz check the files i have attached to see wats wrong in them
Re:problem in printf stuff
Posted: Mon Nov 11, 2002 5:57 pm
by adeelmahmood1
well now i have figured out the problem .. its in the passing argument of my printf function.. ill show u the code to explain the problem
Code: Select all
char testmesg[]="Testing message";
int c_main(){
char *src=testmesg;
char *vidmem = (char *)0xB8000;
int i=1*80*2;
while (*src) {
vidmem[i]=src;
i++;
vidmem[i]=0x07;
i++;
*src++;
}
return 0;
}
this code works fine and print this message
now see this code
Code: Select all
char testmesg[]="Testing message";
aprintf(char *src){
char *vidmem = (char *)0xB8000;
int i=1*80*2;
while (*src) {
destination[i]=src;
i++;
destination[i]=0x07;
i++;
*src++;
}
}
int c_main(){
char *src=testmesg;
aprintf(*src);
return 0;
}
now this code only print <<! on the screen ...
now i dont understand why is it like this .. using the same code .. just using it in another function and calling it from main and the output is different .. plz help me in this
thanx
Re:problem in printf stuff
Posted: Mon Nov 11, 2002 6:26 pm
by Tom
who's printf are you using?
Re:problem in printf stuff
Posted: Mon Nov 11, 2002 6:27 pm
by Tom
oh and can I see your main and that function that doesnt' work?
Re:problem in printf stuff
Posted: Mon Nov 11, 2002 6:39 pm
by adeelmahmood1
check my last reply i have changed it
Re:problem in printf stuff
Posted: Mon Nov 11, 2002 6:47 pm
by Tom
i'll look at it later....can't be on the computer right now....
Re:problem in printf stuff
Posted: Mon Nov 11, 2002 7:47 pm
by Tom
ok...can I see your bootloader, and where your kernel is loaded at? and can I see your GDT (probly in you bootloader/sector)
Re:problem in printf stuff
Posted: Mon Nov 11, 2002 8:43 pm
by _adeelmahmood
well ill post it later coz i m outside now but i dont know what does this problem has to do with that ??
code is infront of u .. if u think the problem is in loader and Gdt and rest of the stuff how it works with the first way