C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How would I write to an address? Posted by KizzoGirl on 12 Aug 2004 at 8:54 PM
I'm looking to right to a specific address. This will explain...

#include <iostream.h>

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;            ?
}


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.

Report
Re: How would I write to an address? Posted by stober on 12 Aug 2004 at 9:06 PM
: 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).
Report
Re: How would I write to an address? Posted by PsychoClown on 12 Aug 2004 at 11:49 PM
: I'm looking to right to a specific address. This will explain...
:
:
: #include <iostream.h>
: 
: 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;            ?
: }
: 

:
: 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:
int *a;

a = (int *)0x0265dda4;
*a = 10;


--
Long live Rock & Roll!

Psycho Clown.





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.