How would I write to an address?

I'm looking to right to a specific address. This will explain...

[code]
#include

int main()
{
int a = 0;

cout<< &a;

// let's say the address of 'a' is 0x265dda4.
// How would I write to the address of 0x265dda4?

// 0x265dda4 = 12; ?
}
[/code]

It doesn't really HAVE to be the address 0x265dda4. It could be anything. My point is, is there any way that C++ can write to a specific address? Arigato.

Comments

  • : It doesn't really HAVE to be the address 0x265dda4. It could be anything. My point is, is there any way that C++ can write to a specific address? Arigato.
    :
    :

    Can't do it with any 32-bit compiler in either *nix or MS Windows. Don't know about MAC (but I suspect that would be forbidden as well). You can do it with 16-bit MS-DOS compiler such as Turbo C but you have to use the segment:offset notation, such as 0004:0020 (one of the interrupt tables).
  • : I'm looking to right to a specific address. This will explain...
    :
    : [code]
    : #include
    :
    : int main()
    : {
    : int a = 0;
    :
    : cout<< &a;
    :
    : // let's say the address of 'a' is 0x265dda4.
    : // How would I write to the address of 0x265dda4?
    :
    : // 0x265dda4 = 12; ?
    : }
    : [/code]
    :
    : It doesn't really HAVE to be the address 0x265dda4. It could be anything. My point is, is there any way that C++ can write to a specific address? Arigato.
    :
    :

    You can access only your address space in protected mode (as in Win32 or Unix), you cannot use far pointers. So you can do this:
    [code]
    int *a;

    a = (int *)0x0265dda4;
    *a = 10;
    [/code]

    --
    Long live Rock & Roll!

    Psycho Clown.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories