Computing.Net > Forums > Programming > Problem with int*

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Problem with int*

Reply to Message Icon

Original Message
Name: Basa
Date: June 26, 2004 at 15:04:30 Pacific
Subject: Problem with int*
OS: Windows XP
CPU/Ram: AMD/256 DDR
Comment:

Hi.

I'm trying to browse through the variables loded to memory with this code:

#include <iostream>
#include <stdlib.h>
#include <stdio.h>

int *a = (int*)0x140000;

int main()
{
FILE* fp;
fp = fopen("test.txt", "w");
if(fp == NULL){
cout << "Eroor: Unable to create file! Program terminates now.\n";
system("pause");
return 0;
}
while (a <= (int*)0x150000){
cout << a << ": " << *a << endl;
fprintf(fp, "%x: %d\n", a, *a);
a++;
}
cout << "Finished!\n";
system("pause");
return 0;
}

Until 0x145ffc it's o.k. but when it reaches 0x146000 it tells me that there's a problem and turns off the application.

P.S.

I'm using Dev-C++ 4, and I recommend it for everybody.

Basa_Melkiy


Report Offensive Message For Removal


Response Number 1
Name: Gargamel
Date: July 11, 2004 at 19:39:19 Pacific
Reply:

What kind of problem it reports?


Report Offensive Follow Up For Removal

Response Number 2
Name: Basa
Date: July 13, 2004 at 13:40:06 Pacific
Reply:

It shows me a dialog window with text:
"basa_test.exe has encountered a problem and needs to close. We are sorry for the inconvenience.
If you were in a middle of something, the information you were working on might be lost.
For more information about this error, click here."

When I click, it says:
"Error signature
AppName: basa_test.exe AppVer: 0.0.0.0 ModName: basa_test.exe
ModVer: 0.0.0.0 Offset: 00001241"
To view technical information about the error report, click here."

When I click this one, it shows me information about the process of the program:
system information, modules the process uses, a thread in hex form and memory ranges in hex form.
below it says:
"The following files will be included in this error report:
C:\DOCUME~1\Basa\LOCALS~1\Temp\WER2.tmp.dir00\appcompat.txt"

And the error continues when I work with ranges from 0x146000 to 0x15fffc, from 0x176000 to 0x17fffc and other ranges too. It only works between that ranges.

Basa_Melkiy


Report Offensive Follow Up For Removal

Response Number 3
Name: Gargamel
Date: July 17, 2004 at 17:58:16 Pacific
Reply:

I'm not sure, but it sounds like the part of memory you are trying to access is protected by the OS or by some other application, probably by a mutex or something.


Report Offensive Follow Up For Removal

Response Number 4
Name: Basa
Date: July 18, 2004 at 14:18:07 Pacific
Reply:

Is there a way to avoid this?
By the way. the same thing happens when I try to do:

int a=5;
cout << (char*)a << endl;

or some other int.

Basa_Melkiy


Report Offensive Follow Up For Removal

Response Number 5
Name: Gargamel
Date: July 18, 2004 at 16:10:26 Pacific
Reply:

In general, programming in a high level language, such as C/C++ suppose to avoid considerations such as explicitly calling memory addresses. The OS suppose to take care of it, and it suppose to be transperant to the programmer.
When uploading your developement tool, it "requests" the OS for a certain portion of memory for its use, including the amount reserved for the user applications, and the OS allocates this portion of the memory. The main idea is that the dev tool, and via that your applications, are not suppose to, and basically not allowed to, use any other parts of the memory, which is what you are trying to do. The only way I can think of avoiding it, is to bypass the OS memory protection, which is barely possible unless you can put your hands on your OS source code. Applications which serve the OS and are not running under the OS, are not submited to the OS restrictions, but in order to write these you need knowledge of the OS construction.
Same goes for the (char*)a case: "a" contains a certain number, and by using (char*)a you are trying to access the memory referenced by "a" (i.e. the address "a" holds) which may be restricted, or, in other case just contain garbage, which cannot be dereferenced.
What is it that you are trying to do exactly? Maybe I'll have a solution...


Report Offensive Follow Up For Removal


Response Number 6
Name: Basa
Date: July 19, 2004 at 15:08:40 Pacific
Reply:

I just tried to view the contents of a variable by knowing only it's memory adress, but as I understood, I can't see it in some adresses.
Thank you for explaining me this.

By the way, can I get the name of the application that is using this variable?

I am just starting with C++ so I may not know some things.

Basa_Melkiy


Report Offensive Follow Up For Removal






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home



Results for: Problem with int*

Problem with C++
    Summary: I have a problem with one of my programms. The source code looks somewhat like this: int function() { char *string, *tempstring; . . strcat(string, tempstring); . . return ret; } Before the call of st...
www.computing.net/answers/programming/problem-with-c/5164.html

java: problem with loop and random
    Summary: I have a problem with a program that generates X numbers of numbers between 1 and 6. X is to be set by an user(Input). The problem is that the result is to be show'n in one JOptionMessageDialog with 5...
www.computing.net/answers/programming/java-problem-with-loop-and-random/7789.html

problem with EnumLineProc
    Summary: I have a problem with the EnumInputLineProc procedure, compilor gives me the error: error C2664: 'EnumerateInputLines' : cannot convert parameter 1 from 'bool (unsigned int,struct tagMIXERLINEA *,unsi...
www.computing.net/answers/programming/problem-with-enumlineproc/4523.html








Which MP3 player do you have?

iPod/iPhone
Zune
Something Else
None


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge
Poll History






Data Recovery Software