Assigning a value to an address

This is a discussion on Assigning a value to an address within the C++ Programming forums, part of the General Programming Boards category; I would like to write a function in C/C++ to copy the letter 'A' to a specific address. This is ...

  1. #1
    stovellp
    Guest

    Assigning a value to an address

    I would like to write a function in C/C++ to copy the letter 'A' to a specific address.

    This is what I have:
    Code:
    int * PAddr = NULL;
    	&PAddr = 0xb8f9e;
    	PAddr = 'a';
    Now that (obviousely) is wrong, but I hope you can understand what I'm asking. There's probably a really simple way to do this, and if there is could you please tell me?

  2. #2
    Back after 2 years Panopticon's Avatar
    Join Date
    Dec 2002
    Posts
    262
    Code:
    PAddr=0x000FFF //or whatever
    *PAddr=824;
    I AM WINNER!!!1!111oneoneomne

  3. #3
    stovellp
    Guest
    Ok, this is what I have:

    Code:
    int * PAddr;
    PAddr= 0xb8f9e  //or whatever
    *PAddr='A';
    When I try to compile I get the error:
    Invalid operands to binary *

    This is with DJGPP.

  4. #4
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by stovellp
    Ok, this is what I have:

    Code:
    int * PAddr;
    PAddr= 0xb8f9e  //or whatever
    *PAddr='A';
    When I try to compile I get the error:
    Invalid operands to binary *

    This is with DJGPP.
    you have to explicitly typecast

    PAddr = reinterpret_cast< int* >( 0xb8f9e );

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Hmmm... Will your OS allow this?

    If you're using WinXP, WinNt, or Win2K, I you'll probably get a run-time error 'cause these operating systems don't allow user-mode programs direct access to memory. I think Win98 will work, but the virtual-paged memory might cause trouble. I also think Linux has similar user-mode protection.
    Last edited by DougDbug; 02-11-2003 at 12:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What does this do (Windows API)?
    By EVOEx in forum Windows Programming
    Replies: 4
    Last Post: 12-19-2008, 10:48 AM
  2. assigning a memory address to a pointer
    By MK27 in forum C Programming
    Replies: 5
    Last Post: 09-16-2008, 02:01 PM
  3. I thought pointers were pointers...
    By keira in forum C Programming
    Replies: 19
    Last Post: 08-16-2007, 12:48 AM
  4. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 07:17 PM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM

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