Is it possible to read a memory address with C++;
For example, If I run this code first:
*************
#include <iostream>
using namespace std;
void main()
{
int *zz = new int;
*zz = 79;
cout << zz << endl;
}
*************
And suppose the output will be 00322E70 .
Now, can I write a new program in C++, and Access the memory address
00322E70 and check what is in there?
So I am thinking of something Like the following code, though the following
DOES NOT WORK:
*************
#include <iostream>
using namespace std;
void main()
{
int *zz;
zz = 00322E70;
cout << *zz << endl;
}
************* 4 13719
Someonekicked wrote: Is it possible to read a memory address with C++;
Not portably, but yes.
For example, If I run this code first:
************* #include <iostream> using namespace std; void main()
int main()
{ int *zz = new int; *zz = 79; cout << zz << endl; } *************
And suppose the output will be 00322E70 .
Now, can I write a new program in C++, and Access the memory address 00322E70 and check what is in there?
It's in the "virtual memory space" of your program. What physical area
it corresponds to in your platform is beyond the scope of the language and
has to be asked about in a newsgroup for your platform.
So I am thinking of something Like the following code, though the following DOES NOT WORK:
************* #include <iostream> using namespace std; void main()
int main()
{ int *zz; zz = 00322E70;
You need to (a) form the literal correctly by prefixing it with '0x' and
(b) use reinterpret_cas t<int*>:
zz = reinterpret_cas t<int*>(0x00322 E70);
However, if that address does not really represent an 'int', using the
pointer resulting from such conversion has undefined behaviour. So, C++
imposes no requirements on that program to do anything in particular.
cout << *zz << endl; } *************
V
Someonekicked wrote: For example, If I run this code first:
************* #include <iostream> using namespace std; void main()
Use Google on this newsgroup for "void main", and for "using namespace std".
From whom are you learning these things?
{ int *zz = new int; *zz = 79; cout << zz << endl; } *************
And suppose the output will be 00322E70 .
Now, can I write a new program in C++, and Access the memory address 00322E70 and check what is in there?
Google for "virtual memory". Each time you run a program, a modern OS will
construct virtual memory for the program, using a secret hardware table of
offsets to real memory. Each time you run the memory could be different.
And all of this is platform specific: The C++ itself won't define the result
of pointing to a memory address that does not contain a well-formed C++
object.
--
Phlip http://www.c2.com/cgi/wiki?ZeekLand
you can use reinterpret_cas t to achieve it but i am looking forward to some
memory violation crashes :)
ben
thx for your reply
"Victor Bazarov" <v.********@com Acast.net> wrote in message
news:Cw******** ********@newsre ad1.mlpsca01.us .to.verio.net.. . Someonekicked wrote: Is it possible to read a memory address with C++;
Not portably, but yes.
For example, If I run this code first:
************* #include <iostream> using namespace std; void main()
int main()
{ int *zz = new int; *zz = 79; cout << zz << endl; } *************
And suppose the output will be 00322E70 .
Now, can I write a new program in C++, and Access the memory address 00322E70 and check what is in there?
It's in the "virtual memory space" of your program. What physical area it corresponds to in your platform is beyond the scope of the language and has to be asked about in a newsgroup for your platform.
So I am thinking of something Like the following code, though the following DOES NOT WORK:
************* #include <iostream> using namespace std; void main()
int main()
{ int *zz; zz = 00322E70;
You need to (a) form the literal correctly by prefixing it with '0x' and (b) use reinterpret_cas t<int*>:
zz = reinterpret_cas t<int*>(0x00322 E70);
However, if that address does not really represent an 'int', using the pointer resulting from such conversion has undefined behaviour. So, C++ imposes no requirements on that program to do anything in particular.
cout << *zz << endl; } *************
V This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sebastian Krause |
last post by:
Hello,
I tried to read in some large ascii files (200MB-2GB) in Python using
scipy.io.read_array, but it did not work as I expected. The whole idea
was to find a fast Python routine to read in arbitrary ascii files, to
replace Yorick (which I use right now and which is really fast, but not
as general as Python). The problem with scipy.io.read_array was, that it
is really slow, returns errors when trying to process large files and it...
|
by: munif |
last post by:
i wnat write a C++ program that would read from a CD and display
information about files and folders in the given CD
In simple words you would be performing a simple (ls -l) or (DIR
/S) on the CD.
LOOk at this code
/*
|
by: hvaisane |
last post by:
Valgrind says
==11604== Invalid read of size 4
==11604== at 0x8048ABB: main (foo.cc:36)
==11604== Address 0x1B92415C is 4 bytes inside a block of size 8 free'd
==11604== at 0x1B90514F: operator delete(void*) (vg_replace_malloc.c:156)
==11604== by 0x804A1BA: __gnu_cxx::new_allocator<Foo>::deallocate(Foo*, unsigned) (new_allocator.h:86)
==11604== by 0x8049C08: std::_Vector_base<Foo, std::allocator<Foo> >::_M_deallocate(Foo*,...
|
by: Holger Hasselbach |
last post by:
- The value of the object allocated by the malloc function is used
(7.20.3.3).
- The value of any bytes in a new object allocated by the realloc
function beyond the size of the old object are used (7.20.3.4).
Something like this (include and checkings omitted):
p = malloc(sizeof(*p) * 5);
p = 1; p = 1; p = 1;
|
by: Mark Richards |
last post by:
I've been programming for many years, but have only recently taken a
deep "C" dive (bad pun, i know) and need a lot of explanation from an
expert. My questions center around those mysterious pointer beasties.
The following code is excerpted from digitemp, a program that reads
1-wire devices. Digitemp is the work of Brian C. Lane.
As I walk through this code, I have a number of questions. I'm hoping
someone with experience in...
| |
by: Pete |
last post by:
I having a problem reading all characters from a file. What I'm trying to
do is open a file with "for now" a 32bit hex value 0x8FB4902F which I want
to && with a mask 0xFF000000 then >> right shift 24 bits storing in result
then printing the result.
I thing a while or for loop is needed but I'm not quite sure how to go about
it. How do I step through each character in this case and store it for use
and passing to another function.
...
|
by: Brad |
last post by:
Hi,
Am trying to read one byte at location 0xFFF0 000E in an embedded system.
I cast a pointer to int, then try to stuff the above address in, then
reference whats at the location? wont compile, tried many different
variations of this; any ideas appreciated.
|
by: alexandre_irrthum |
last post by:
Hi there,
I am trying to use pyserial to read data from a temperature logger
device (T-logger). T-logger is based on the DS1615 temperature recorder
chip (Dallas Semiconductor). According to the DS1615 docs, writing to
the chip is performed one byte at a time. To read from the chip, one
must issue the "read page" command (33h), followed by the two-byte
address of the requested page (pages are 32 bytes long). After
receiving this, the...
|
by: tlpell |
last post by:
Hey, read some tips/pointers on PHP.net but can't seem to solve this
problem. I have a php page that reads the contents of a file and then
displays the last XX lines of the file. Problem is this...whenever
the file gets larger that ~5MB, the page just displays nothing, as
though a timeout has occurred but I get no error. At 4.8MB (last
confirmed size)...the function still works. Any ideas what code below
is lacking??
<?
$handle=...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |