Thread: 'Manually' give adress to pointer

  1. #1
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Breukelen, The Netherlands

    'Manually' give adress to pointer

    Why isn't it possible to 'manually' give a pointer the adress of a variable?
    int Integer;
    int * Pointer;
    Pointer = 0x22ff70;
    //Instead of: Pointer = & Integer;

  2. #2
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Breukelen, The Netherlands
    Note: I know that people shouldn't program like this but I only wanna know How To give a pointer an adress like that, it gives compile errors.

  3. #3
    Registered User
    Join Date
    Aug 2005
    you can not do that with any 32-bit compiler because the os prevents a program from accessing physical memory that it does not own. In 16-bit MS-DOS 6.X compilers, such as Tur bo C, that was easy to do because the program had access to all available memory below the first meg. In 32-bit os such as MS-Windows and *nix an address such as 0x22ff70 can be anywhere including the os itself or some other program that is running.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Of course you can do it
    Pointer = (int*)0x22ff70;

    Now whether your OS will allow you to dereference that pointer, or whether your hardware has any memory mapped at that address is another matter.

    It doesn't make sense to do this in normal user-space programs on your desktop operating systems, but you see this in driver-space code and embedded systems all the time.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 05-15-2009, 08:38 AM
  2. Ban pointers or references on classes?
    By Elysia in forum C++ Programming
    Replies: 89
    Last Post: 10-30-2007, 03:20 AM
  3. sorting with pointer of pointers to array
    By dunpealslyr in forum C++ Programming
    Replies: 6
    Last Post: 10-01-2007, 11:26 PM
  4. Adress of a pointer.
    By ozumsafa in forum C Programming
    Replies: 2
    Last Post: 09-21-2007, 02:59 AM
  5. file pointer
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-11-2001, 03:52 PM