Page 1 of 1

Strange Behaviour in C

Posted: Sun Nov 17, 2002 1:30 am
by PlayOS
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:

Code: Select all

   char* video = (char*)0xb8000;
   *video = 'A';
   video++;
   *video = 0x1e;
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:

Code: Select all

   char* video = (char*)0xb8000;
   video[0] = 'A';
   video[1] = 0x1e;
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:

Code: Select all

   variable++;
   variable += 1;
   variable = variable + 1;
Has anyone seen this before? or does anyone have any advice for me?

Thanks.

Re:Strange Behaviour in C

Posted: Sun Nov 17, 2002 2:40 am
by PlayOS
Sorry, I should have posted this in the Programming Forum. ::)

Edit : In fact now I have so you can help me out over there if you prefer.