'Manually' give adress to pointer

This is a discussion on 'Manually' give adress to pointer within the C++ Programming forums, part of the General Programming Boards category; Hi. Why isn't it possible to 'manually' give a pointer the adress of a variable? Example: Code: int Integer; int ...

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

    'Manually' give adress to pointer

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

  2. #2
    Banned Yuri's Avatar
    Join Date
    Aug 2005
    Location
    Breukelen, The Netherlands
    Posts
    133
    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
    Posts
    1,267
    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
    Location
    The edge of the known universe
    Posts
    32,822
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21