C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

System error on pointer program

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Protoman
Guest





PostPosted: Tue Feb 28, 2006 5:06 am    Post subject: System error on pointer program Reply with quote



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!!!!
Back to top
Victor Bazarov
Guest





PostPosted: Tue Feb 28, 2006 5:06 am    Post subject: Re: System error on pointer program Reply with quote



Protoman wrote:
Quote:
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?

Quote:
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_.

Quote:
system("PAUSE");
return EXIT_SUCCESS;
}

Why does it keep crashing?

Your program has undefined behaviour. It can do whatever it pleases.

Quote:
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
Back to top
Rolf Magnus
Guest





PostPosted: Tue Feb 28, 2006 2:06 pm    Post subject: Re: System error on pointer program Reply with quote



Protoman wrote:

Quote:
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.

Quote:
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.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.