By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,902 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

address in memory

P: n/a
tom
He
How to get address in memory?

for example:
I would like 'ADR' be the adress in memory where 'srtBuf' starts
from debuger I know it is 0x003b1460 but how to get it by program?

char* srtBuf = new char[20];
long int ADR = 0x003b1460;

t.
Sep 21 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
tom napisał(a):
He
How to get address in memory?

for example:
I would like 'ADR' be the adress in memory where 'srtBuf' starts
from debuger I know it is 0x003b1460 but how to get it by program?

char* srtBuf = new char[20];
long int ADR = 0x003b1460;

t.

intptr_t ADR = reinterpret_cast<intptr_t>(srtBuf);

--
Marcin Gabryszewski
G DATA Software
www.gdata.pl

address:<FirstName><dot><Surname><at><gdata><dot>< pl>
Sep 21 '06 #2

P: n/a
tom wrote:
for example:
I would like 'ADR' be the adress in memory where 'srtBuf' starts
char* srtBuf = new char[20];
long int ADR = 0x003b1460;
Simple:

void* ADR = srtBuf;

A void* is what you use to denote an address in memory when you don't
care about the type. You can print it using std::cout << ADR <<
std::endl;

HTH,
Michiel Salters

Sep 21 '06 #3

P: n/a

"tom" <ee@w.ewrote in message news:ee**********@atlantis.news.tpi.pl...
He
How to get address in memory?

for example:
I would like 'ADR' be the adress in memory where 'srtBuf' starts
from debuger I know it is 0x003b1460 but how to get it by program?

char* srtBuf = new char[20];
long int ADR = 0x003b1460;
The srtBuf variable is a pointer. It holds the address of the start of the
buffer. If you want a long int variable to hold a pointer address, just
assign it, with a cast:

long int ADR = reinterpret_cast<long int>(srtBuf);

Note: This assumes that a pointer can fit in a long int on your system. On
some systems, addresses may be longer (or shorter) than a long int. (I'm
guessing that's why Marcin used intptr_t. But you used a long int, so I
showed how to use that.)

-Howard
Sep 21 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.