473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

System error on pointer program

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!!!!

Feb 28 '06 #1
2 1579
Protoman wrote:
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
--
Please remove capital As from my address when replying by mail
Feb 28 '06 #2
Protoman wrote:
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.

Feb 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Christian Christmann | last post by:
Hi, assert and error handling can be used for similar purposes. When should one use assert instead of try/catch and in which cases the error handling is preferable? I've read somewhere that...
14
by: prasadjoshi124 | last post by:
Hi All, I am writing a small tool which is supposed to fill the filesystem to a specified percent. For, that I need to read how much the file system is full in percent, like the output given...
1
by: urkel | last post by:
Hi everyone, I critically need help to solve this problem related to pointer in C++ Basically, I have a C/C++ program "retardselfenerg" calling a Fortran 90 subroutine "surfGF4.f90". i am so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.