Page 2 of 2

Re:Physical Memory Layout

Posted: Tue Sep 09, 2003 3:39 am
by mystran
Solar wrote: Because that construct is correct.
Agreed.
But try to come up with a char* to 0xb8000 that doesn't throw a warning with -pedantic. The solution is

Code: Select all

char* ptr = 0;
ptr += 0xb8000;
and potentially non-portable because pointer arithmetics are only defined within the same array (and there is no char* array starting at 0 because 0 must not point to a valid object). Add to this that ptr is not required by the standard to actually point to address 0 (as we discussed in this thread)... you could, theoretically, end up just about anywhere.
The thing is, when writing portable C, you should never need to come up with a pointer to a specific address.

Anyhow, are you sure pointer arithmetics are not defined outside arrays.. I've never seen anything that would claim this to be true, and the point is, it makes malloc useless for things like strings... then again.. there's calloc().

Let's all from now on allocate our strings with calloc(len,sizeof(char)); We should also probably not rely on char being 8bits or int 32bits since char could just as well be 7bits and int 25bits, or pretty much anything else, as long as sizeof(char)<=sizeof(short)<=sizeof(int)<=sizeof(long).

This actually gave me an insight. At some point I'm supposed to have a uni class of C. I happen to know that the professor happens to want (supposedly) standard C99 so I better remember all the pain of using pointers portably then. He's gonna have fun with that calloc()..

Re:Physical Memory Layout

Posted: Tue Sep 09, 2003 3:42 am
by Pype.Clicker
hmm ...
maybe

Code: Select all

   asm volatile("movl $0xb8000, %0":"=g"(ptr));
would be the sole clean option ... Or have an extern char array Video[] which address would be set by the linker script to be 0xB8000 ...

However, the address of the video memory (or any fixed absolute address i can think of atm) is platform-specific, so what would a "portable" code mean in that context, anyway ? There's no portable way to set a pointer to video memory, nor to page directories or whatever ...

Re:Physical Memory Layout

Posted: Tue Sep 09, 2003 4:34 am
by Solar
Both solutions are outside the scope of C/C++. ;-)
Pype.Clicker wrote: However, the address of the video memory (or any fixed absolute address i can think of atm) is platform-specific, so what would a "portable" code mean in that context, anyway ?
That's probably the reason why the committees didn't feel a portable way to set a pointer to X is necessary.