char *vidmem=(char *)0xb8000

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
slacker

Re:char *vidmem=(char *)0xb8000

Post by slacker »

Tim Robinson wrote: By "hack", I mean "code which isn't compliant with the ISO C Standard". You're breaking the C Standard by merely writing an operating system
well im hearing two different things.....
Whatever5k

Re:char *vidmem=(char *)0xb8000

Post by Whatever5k »

The type cast is totally fine, use it. I do not understand the problem you have with it. Tim was referring to your code:

Code: Select all

pointer = 0xb8000;
_This_ is indeed something which is not ISO-C compliant. Use following instead which *is* ISO-C compliant:

Code: Select all

char *pointer = (char *) 0xb8000;
End of story ;)
nullify

Re:char *vidmem=(char *)0xb8000

Post by nullify »

Tim Robinson wrote: Assigning an int to a pointer is a hack which will only work on machines with a flat address space, so you need the cast to let you do it.
Tim never said that type casting is against the ISO C standard! The only problem is when you don't explicity tell the compiler what you are intending to do. In other words, there is nothing hackish about doing:

Code: Select all

char *vidmem = (char *)0xb8000;
There's nothing wrong with doing this to reference memory.
slacker

Re:char *vidmem=(char *)0xb8000

Post by slacker »

aah i see. i thought he meant that type casting was a hack and wasnt compilant with the standard
slacker

Re:char *vidmem=(char *)0xb8000

Post by slacker »

why is writing an OS breaking the C standard (according to Tim) ?
Therx

Re:char *vidmem=(char *)0xb8000

Post by Therx »

The C standard includes what should be in the C library etc. Now I'm sure that your OS doesn't have a complete libC which makes it not compliant
slacker

Re:char *vidmem=(char *)0xb8000

Post by slacker »

thanks to all this posting i finally see what is going on

(char *)0xb8000; <---makes to pointer from an integer

vidmem=(char *)0xb8000 <-----setting the video pointer equal to the pointer which points to the video memory

yes! i should of caught this on the first response but im slow.
Tim

Re:char *vidmem=(char *)0xb8000

Post by Tim »

slacker wrote:why is writing an OS breaking the C standard (according to Tim) ?
Well, on the x86, you've got to use assembly language somewhere. If that's not inline then you're breaking the standard by using the asm extension (which is pretty common).

The ISO C Standard provides for freestanding and hosted implementations of C. A hosted implementation is what you'll use under a full OS, with main, <stdio.h>, and everything else. A freestanding implementation consists of the language itself, a few header files consisting only of #defines (no library functions), and not much else.

By writing an OS you can conform to a freestanding implementation. And by writing an OS, you can provide an environment for other people to write hosted programs.
Post Reply