471,605 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Assing address to pointer

In the following code:

unsafe class X
{
byte* _address;
void test()
{
_address=(byte*)144220152;
}

}

Why the watch windows shows a differtent address for _address variable
?

Jan 9 '06 #1
10 2807
Vlad,

Are you sure you are not looking at the hexidecimal format for the
number? Does it show you 8989FF8 instead (this is the same value in hex
format)?

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Vlad" <a.*********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
In the following code:

unsafe class X
{
byte* _address;
void test()
{
_address=(byte*)144220152;
}

}

Why the watch windows shows a differtent address for _address variable
?

Jan 9 '06 #2
Thanks for your help, but the problem isn't hexidecimal format

Jan 9 '06 #3
Vlad,

Well, I changed the _address field and the test method to be public, and
then wrote the value of _address out to the console after I ran test. The
value was the same.

There must be something else changing it which is not shown in the code
that you posted.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Vlad" <a.*********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
In the following code:

unsafe class X
{
byte* _address;
void test()
{
_address=(byte*)144220152;
}

}

Why the watch windows shows a differtent address for _address variable
?

Jan 9 '06 #4

"Vlad" <a.*********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
| In the following code:
|
| unsafe class X
| {
| byte* _address;
| void test()
| {
| _address=(byte*)144220152;
| }
|
| }
|
| Why the watch windows shows a differtent address for _address variable
| ?
|

_address is located on the stack and it's a pointer so the stack location
will hold the value you set by _address=(byte*)144220152;
To find the value of byte* you'll have to look at the contents of this
location.

Willy.
Jan 9 '06 #5
I change the question: What is the largest address that I can assign
to pointer ?

Jan 10 '06 #6
I know, I'm interested at the address of pointer rather the value

Jan 10 '06 #7

"Vlad" <a.*********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
|I know, I'm interested at the address of pointer rather the value
|

What do you mean by that?

_address is a variable located on the stack, you set the contents of this
location to 144220152 by this assignment:

_address=(byte*)144220152; // set _address to 0x08989ff8

So suppose your _address is at 0x00125604; after the assignment, the int
value at 0x00125604 will contain 0x08989ff8.
Note that the value will be DWORD swapped, so the debugger will show
0xf89f9808.

Willy.


Jan 10 '06 #8

"Vlad" <a.*********@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
|I change the question: What is the largest address that I can assign
| to pointer ?
|

The largest user address on 32 bit windows is 0x7fffffff (decimal
2147483647), note that while you can point to anything between 0 and
0x7fffffff in your address space, it does not mean that read or write
from/to anything. What exactly are you trying to achieve.

Willy.
Jan 10 '06 #9

Thanks for your patience this is the last post in the thread
It's wrong think that the following code in c# are equivalent?
byte* p;
p=someAddress

----------------------------------------------------
IntPtr p=new IntPtr(someAddress)
The pointers are address container?

Jan 10 '06 #10

"Vlad" <a.*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
|
| Thanks for your patience this is the last post in the thread
| It's wrong think that the following code in c# are equivalent?
|
|
| byte* p;
| p=someAddress
|
| ----------------------------------------------------
| IntPtr p=new IntPtr(someAddress)
|
|
| The pointers are address container?
|

More or less;
case1: p is a variable that holds a pointer that points to a byte.
case2: p is a variable that holds a pointer to a void type.

Willy.
Jan 10 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by johny smith | last post: by
9 posts views Thread by Cheney Stallman | last post: by
35 posts views Thread by hasho | last post: by
15 posts views Thread by dandelion | last post: by
7 posts views Thread by realgeek | last post: by
57 posts views Thread by Robert Seacord | last post: by
54 posts views Thread by John | last post: by
36 posts views Thread by Julienne Walker | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

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.