well im hearing two different things.....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
char *vidmem=(char *)0xb8000
Re:char *vidmem=(char *)0xb8000
Re:char *vidmem=(char *)0xb8000
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
Code: Select all
pointer = 0xb8000;
Code: Select all
char *pointer = (char *) 0xb8000;
Re:char *vidmem=(char *)0xb8000
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: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.
Code: Select all
char *vidmem = (char *)0xb8000;
Re:char *vidmem=(char *)0xb8000
aah i see. i thought he meant that type casting was a hack and wasnt compilant with the standard
Re:char *vidmem=(char *)0xb8000
why is writing an OS breaking the C standard (according to Tim) ?
Re:char *vidmem=(char *)0xb8000
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
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.
(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
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).slacker wrote:why is writing an OS breaking the C standard (according to Tim) ?
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.