Page 3 of 3
Re:char *vidmem=(char *)0xb8000
Posted: Mon Jul 07, 2003 8:14 am
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.....
Re:char *vidmem=(char *)0xb8000
Posted: Mon Jul 07, 2003 8:37 am
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:
_This_ is indeed something which is not ISO-C compliant. Use following instead which *is* ISO-C compliant:
End of story
Re:char *vidmem=(char *)0xb8000
Posted: Mon Jul 07, 2003 8:42 am
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:
There's nothing wrong with doing this to reference memory.
Re:char *vidmem=(char *)0xb8000
Posted: Mon Jul 07, 2003 8:47 am
by slacker
aah i see. i thought he meant that type casting was a hack and wasnt compilant with the standard
Re:char *vidmem=(char *)0xb8000
Posted: Mon Jul 07, 2003 8:50 am
by slacker
why is writing an OS breaking the C standard (according to Tim) ?
Re:char *vidmem=(char *)0xb8000
Posted: Mon Jul 07, 2003 9:36 am
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
Re:char *vidmem=(char *)0xb8000
Posted: Mon Jul 07, 2003 11:01 am
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.
Re:char *vidmem=(char *)0xb8000
Posted: Mon Jul 07, 2003 4:26 pm
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.