Feeling kind of stupid about pointers

Discussion in 'C++' started by PullnOutHair, Jul 29, 2004.

  1. PullnOutHair

    PullnOutHair Guest

    I know that I should know how to do this, but for some reason it is
    escapeing me right now and I was hoping someone here could help. I
    need to setup a pointer to the memory location 0x30000000. I am
    working on a linux system that has hardware inputs remapped to that
    address and I have to read them. I am just drawing a blank on how to
    actually assign the address of a pointer to point to.
     
    PullnOutHair, Jul 29, 2004
    #1
    1. Advertisements

  2. PullnOutHair

    red floyd Guest

    You don't do it in userland. That said.


    assert(sizeof(void*) >= sizeof(unsigned long))
    void* ptr = reinterpret_cast<void*>(0x30000000UL);
     
    red floyd, Jul 29, 2004
    #2
    1. Advertisements

  3. PullnOutHair

    PullnOutHair Guest

    What do you mean?
     
    PullnOutHair, Aug 4, 2004
    #3


  4. Assuming that the platform will allow you, and assuming the pointer is
    of type whatever, you can do:



    whatever *p = reinterpret_cast<whatever *>(0x30000000);






    Regards,

    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Aug 4, 2004
    #4
  5. Jonathan Turkanis, Aug 4, 2004
    #5
  6. PullnOutHair

    JKop Guest

    Ioannis Vranos posted:
    Should the "volatile" keyword be in there at all?

    -JKop
     
    JKop, Aug 4, 2004
    #6
  7. PullnOutHair

    red floyd Guest

    Depends on whether it's data that can change out from underneath him.

    My favorite variant of this (embedded system, C, not C++) was:

    const volatile unsigned long * const PREGISTER =
    (const volatile unsigned long *) 0xC0000000L;

    It was a read-only memory mapped register.
     
    red floyd, Aug 4, 2004
    #7

  8. volatile is used when the value of the variable can change between reads
    outside of the program (e.g. an external thermometer). It has as a
    result the compiler to not perform some optimisations.






    Regards,

    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Aug 5, 2004
    #8
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.