System error on pointer program

P

Protoman

I'm getting a system error on this piece of code on WinXP:

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
volatile int* p=reinterpret_cast<int*>(0x59861);
for(int i=0;i<20;i++)
cout << *p << endl;
system("PAUSE");
return EXIT_SUCCESS;
}

Why does it keep crashing? And what's the mem address of the system
clock for WinXP? Thanks!!!!
 
V

Victor Bazarov

Protoman said:
I'm getting a system error on this piece of code on WinXP:

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
volatile int* p=reinterpret_cast<int*>(0x59861);

Where is any guarantee that '0x59861' is a pointer to an int?
for(int i=0;i<20;i++)
cout << *p << endl;

You're dereferencing a pointer here which is most likely invalid,
which constitutes _undefined_behaviour_.
system("PAUSE");
return EXIT_SUCCESS;
}

Why does it keep crashing?

Your program has undefined behaviour. It can do whatever it pleases.
And what's the mem address of the system
clock for WinXP? Thanks!!!!

Shouldn't you ask this in a WinXP newsgroup?

V
 
R

Rolf Magnus

Protoman said:
I'm getting a system error on this piece of code on WinXP:

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
volatile int* p=reinterpret_cast<int*>(0x59861);
for(int i=0;i<20;i++)
cout << *p << endl;
system("PAUSE");
return EXIT_SUCCESS;
}

Why does it keep crashing?

It probably has something to do with you trying to access a specific
address. Probably this address isn't a valid one, so your OS decides to
terminate your program.
And what's the mem address of the system clock for WinXP? Thanks!!!!

No idea. But under modern operating systems, you usually don't get direct
access to specific memory locations. On such OSs, the addresses you are
using are typically not even real memory addresses, but rather part of a
virtual address space created for your program. You're supposed to access
specific hardware through driver interfaces of your system. This is to
prevent programs from bringing the whole system down by messing up the
hardware.
How to do that, you best ask in a newsgroup about WinXP programming.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top