Stop Microsoft

Miscellaneous => Programming & Networking => Topic started by: anphanax on 17 December 2003, 21:59

Title: Casting with pointers?
Post by: anphanax on 17 December 2003, 21:59
First off, let me explain what i'm doing. I'm accessing VRAM (The VGA/EGA Offset) in a 320x200, 256 color environment. (Not that annoying 4-layer crap)

/* This Works */
unsigned char far *videoRAM = (unsigned char far *)0xA0000000L;

/* This Doesn't:
   ERROR: Cannot convert 'unsigned long' to
   'unsigned char*' */
unsigned char far *videoRAM = 0xA0000000L;

Why do I need casting on memory locations?
It's a location in memory, and has nothing
really todo with the datatype, so i'm a bit
confused.

I posted this here because I tried getting an answer in a "computer" chat and no one seemed to know what I was talking about.

[ December 17, 2003: Message edited by: anphanax ]

Title: Casting with pointers?
Post by: Refalm on 17 December 2003, 13:39
quote:
anphanax: Why do I need casting on memory locations? It's a location in memory, and has nothing really todo with the datatype, so i'm a bit confused.


Are you talking about the BIOS or the RAM? I'm confused now too  :confused:
Title: Casting with pointers?
Post by: flap on 17 December 2003, 18:14
It's just standard type-checking practice, and it depends on the compiler you're using. GCC (which I assume you're not using) would let you do it without a cast but would give you a warning.
Title: Casting with pointers?
Post by: anphanax on 18 December 2003, 01:23
Thanks for your help.