problem in printf stuff
Re:problem in printf stuff
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.
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:
Code: Select all
aprintf(&message, 1);
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
ok i will try what u have told me to do .. lets see how it works .. but u said
can u explain this plz
thanx
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.hit is a really bad practice in C to put actual functions in a header file
can u explain this plz
thanx
Re:problem in printf stuff
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:
But the actual printf() and putc() function are hold in .c files.
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 );
...
...
Re:problem in printf stuff
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
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
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
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
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
this code works fine and print this message
now see this code
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
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;
}
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 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
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
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
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