Strange Behaviour in C
Posted: Sun Nov 17, 2002 1:30 am
Hi,
I am at quite a loss as to why C is doing this, it is very strange. I first noticed the problem when I attempted the Kernel in C++ tutorial posted here. For some reason the variables will not increment.
It sounds weird but it is happening, look at this code for example:
this code should write a yellow on blue 'A' at 0,0 on the screen, however it comes up with a weird triangle character, this character is produced by the 0x1e, so instead of the video variable being incremented, it is just overwriting the first byte of video memory. If I write the same code like this:
then everything goes according to plan. This is really puzzling because I have never seen this before.
I cannot increment variables in any way, none of the following ways work:
Has anyone seen this before? or does anyone have any advice for me?
Thanks.
I am at quite a loss as to why C is doing this, it is very strange. I first noticed the problem when I attempted the Kernel in C++ tutorial posted here. For some reason the variables will not increment.
It sounds weird but it is happening, look at this code for example:
Code: Select all
char* video = (char*)0xb8000;
*video = 'A';
video++;
*video = 0x1e;
Code: Select all
char* video = (char*)0xb8000;
video[0] = 'A';
video[1] = 0x1e;
I cannot increment variables in any way, none of the following ways work:
Code: Select all
variable++;
variable += 1;
variable = variable + 1;
Thanks.