Page 1 of 1
Printing to the screen
Posted: Sat Mar 07, 2009 10:38 pm
by gsingh2011
This code is giving me the errors:
Source Files/kernel.c:17: error: expected ‘;’ before ‘)’ token
Source Files/kernel.c:17: error: expected expression before ‘)’ token
but I have all of my ; in the right places so I can't figure out what's wrong with it...
Code: Select all
volatile unsigned char* videoram = (volatile unsigned char *) 0xb8000;
void printstr(char string[])
{
int i = 0;
for (i = 0, i < 2, i++)
{
videoram[2*i] = string[i];
videoram[1+(2*i)] = 0x07;
}
}
void kmain( void* mbd, unsigned int magic )
{
printstr("Hi");
}
Re: Printing to the screen
Posted: Sat Mar 07, 2009 10:51 pm
by Firestryke31
Is that the whole file as it appears? I'm guessing not, seeing as there's not even 17 lines there. I'd also guess that line 17 is the "void printstr(char string[])" but I may be wrong. IIRC you can't pass variable length arrays in C/C++, but I've always used the fact that (code wise) pointers and arrays are practically interchangeable, so I may be wrong. I would have used "void printstr(char *string)" instead. The function itself would be the same.
Re: Printing to the screen
Posted: Sat Mar 07, 2009 10:54 pm
by neon
This is an error. The comma operator has a different function then the use of the semicolon which is used to end expressions. Thus you need to use semicolons not colons. (This is basic C...)
Re: Printing to the screen
Posted: Sat Mar 07, 2009 10:59 pm
by gsingh2011
Ah.. Thanks. It's one of those things that happens when you've been sitting at a computer too long..
Anyway, it compiles without errors now but nothing shows up when I run it. Anyone know why?
Re: Printing to the screen
Posted: Sat Mar 07, 2009 11:03 pm
by neon
If you are building it with GCC, insure your linker script has a .rodata section in it.
Re: Printing to the screen
Posted: Sat Mar 07, 2009 11:04 pm
by Firestryke31
Wow, I completely missed that. I've been staring at ASM for too long...
Re: Printing to the screen
Posted: Sat Mar 07, 2009 11:26 pm
by Troy Martin
Firestryke31 wrote:I've been staring at ASM for too long...
That's how I feel every time I look at C and find bazillions of things I think are wrong in the code.
Re: Printing to the screen
Posted: Sun Mar 08, 2009 6:09 am
by Combuster
Okay, you should so seriously not write an OS. You can't write code, you can't debug code. You just failed the required knowledge test.
Go start with the basics and see you again in a year (at the least!)