Author Topic: Casting with pointers?  (Read 995 times)

anphanax

  • Member
  • **
  • Posts: 197
  • Kudos: 11
    • http://june.tripod.com
Casting with pointers?
« 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 ]


Refalm

  • Administrator
  • Member
  • ***
  • Posts: 5,183
  • Kudos: 704
  • Sjembek!
    • RADIOKNOP
Casting with pointers?
« Reply #1 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:

flap

  • Member
  • **
  • Posts: 1,268
  • Kudos: 137
Casting with pointers?
« Reply #2 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.
"While envisaging the destruction of imperialism, it is necessary to identify its head, which is none other than the United States of America." - Ernesto Che Guevara

http://counterpunch.org
http://globalresearch.ca


anphanax

  • Member
  • **
  • Posts: 197
  • Kudos: 11
    • http://june.tripod.com
Casting with pointers?
« Reply #3 on: 18 December 2003, 01:23 »
Thanks for your help.