Thread: Pointer and typecasting question

  1. #1
    Registered User
    Join Date
    Sep 2006
    Location
    Beaverton, Oregon, United States
    Posts
    176

    Pointer and typecasting question

    This is a piece of code from the C setup of a cross platform console system.

    Now I'm a bit familiar with pointers and typecasting, however this setup is confusing to me.

    Code:
    *(unsigned short int *) 0xf00400 = 0x0000; /* Color reg 0 = black */
      *(unsigned short int *) 0xf00402 = 0xffff; /* Color reg 1 = white */
    Now I know its a typecast but I'm use to seeing them something like this:

    n3.next=( struct entry *) 0; or somesuch.

    Can someone clarify for me what kind of pointer setup this is? a hex pointer?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    All variables hold values - numbers really - and this is just skipping the step of actually having a variable. You telling the compiler that the value represents the value a pointer would normally be storing (a spot in memory), and manipulating that spot directly. There's a good chance your OS is going to frown upon that.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Location
    Beaverton, Oregon, United States
    Posts
    176
    Thanks for your insight.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Location
    Beaverton, Oregon, United States
    Posts
    176
    Quote Originally Posted by quzah View Post
    All variables hold values - numbers really - and this is just skipping the step of actually having a variable. You telling the compiler that the value represents the value a pointer would normally be storing (a spot in memory), and manipulating that spot directly. There's a good chance your OS is going to frown upon that.


    Quzah.
    oh ok so its basically pointing directly at a memory location '0xf00400' and sticking the value '0x0000' in there?

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Yes. And furthermore treating that memory destination as "short" - which is a 2-byte (16 bit value). So the 0x0000 and 0xffff will mash 2 bytes each. No more, no less.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. typecasting?
    By tammo21 in forum C Programming
    Replies: 6
    Last Post: 08-17-2002, 04:19 AM
  2. Pointer Question
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 08-06-2002, 10:40 AM
  3. Another Pointer Question
    By pr0ficient in forum C Programming
    Replies: 5
    Last Post: 07-17-2002, 02:45 AM
  4. Problem with Typecasting
    By pinkcheese in forum C++ Programming
    Replies: 4
    Last Post: 04-14-2002, 03:26 AM
  5. question about pointer?
    By pnxi in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 01:45 PM