Code: Select all
unsigned char *testb = (unsigned char*) 0x300000;
printf("%d\n", *testb);
*testb = "Q";
printf("%s\n", *testb);
What's wrong? My OS has no multitasking, so nothing can overwrite 0x300000...
Code: Select all
unsigned char *testb = (unsigned char*) 0x300000;
printf("%d\n", *testb);
*testb = "Q";
printf("%s\n", *testb);
The ASCII character 'Q' has the value 0x51, so "printf("%s\n", *testb);" prints the string at address 0x0000051.Roman wrote:I have the following code:Code: Select all
unsigned char *testb = (unsigned char*) 0x300000; printf("%d\n", *testb); *testb = "Q"; printf("%s\n", *testb);
Either you use a crappy compiler, or you ignored the warning:Roman wrote:*testb = "Q";
Looks like your OS is happy.Roman wrote:What's wrong? My OS has no multitasking, so nothing can overwrite 0x300000...
You don't know enough C, that's what's wrong.Roman wrote:I have the following code:What's wrong? My OS has no multitasking, so nothing can overwrite 0x300000...Code: Select all
unsigned char *testb = (unsigned char*) 0x300000; printf("%d\n", *testb); *testb = "Q"; printf("%s\n", *testb);
Code: Select all
unsigned char *testb = (unsigned char*) 0x300000;
Code: Select all
printf("%d\n", *testb);
Code: Select all
*testb = "Q";
Code: Select all
printf("%s\n", *testb);
Forgive me for pointing this out, but if you're writing an OS in C, you really should be good at C . In fact, if you don't know C, you probably shouldn't be writing an OS at all! Even if you were writing an OS 100% in assembly, just about every low-level programmer knows C, and if you don't it could be a sign that you don't know much about programming in low-level languages in general.Roman wrote:My OS laughs at my C skills.