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

difference between address and pointer

P: n/a
Hi All.

I would like to know the following information.

1)Is there any difference between the address and integer ?

For example suppose int x = 500;
And int y =10;
Suppose address of y is also 500;
My doubt is there any difference between the properties of value of x
and address of y which is 500.

Regards,
Somenath
Int x =500;

Aug 9 '07 #1
Share this Question
Share on Google+
16 Replies


P: n/a
somenath wrote:
I would like to know the following information.

1)Is there any difference between the address and integer ?
Addresses (and pointers) are different from integers.
For example suppose int x = 500;
And int y =10;
Suppose address of y is also 500;
It isn't. 500 is an integer; the address of y is a pointer. They
are two distinguishable types /even if/ the underlying machine uses
integer-like bit-patterns as pointers and integer arithmetic to
do address calculations.
My doubt is there any difference between the properties of value of x
and address of y which is 500.
Yes. For example, it's legal to multiply an integer by another integer,
but not to multiply an address by an integer. Integer values can
be assigned to floating variables; addresses cannot. You cannot
dereference an integer. Etc.

--
Chris "almost but not quite completely different" Dollin

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

Aug 9 '07 #2

P: n/a
somenath wrote:
Hi All.

I would like to know the following information.

1)Is there any difference between the address and integer ?

For example suppose int x = 500;
And int y =10;
Suppose address of y is also 500;
My doubt is there any difference between the properties of value of x
and address of y which is 500.
This question is regularly thrashed over in the group. A little scanning
in Google Groups would probably find the most recent discussion...

Two points for now:-
1) The format of a pointer is not defined by the C standard
2) Not all systems have "flat" address spaces, so the idea that an
address is an integer is not portable.
Aug 9 '07 #3

P: n/a
somenath wrote On 08/09/07 10:12,:
Hi All.

I would like to know the following information.

1)Is there any difference between the address and integer ?

For example suppose int x = 500;
And int y =10;
Suppose address of y is also 500;
My doubt is there any difference between the properties of value of x
and address of y which is 500.
Other respondents have explained that a pointer is
not an integer, by showing that an address is not an
integer. But the difference goes even deeper: a pointer
is not just an address. Contemplate this code fragment
for a while, and you'll understand why a pointer is more
than an address:

union { double d; int i; } u;
double *dp = &u.d;
int *ip = &u.i;

In this code, the two pointers dp and ip point to the
same memory location. Nonetheless, they are different.
What makes them different?

--
Er*********@sun.com
Aug 9 '07 #4

P: n/a
somenath wrote:
>
I would like to know the following information.

1)Is there any difference between the address and integer ?

For example suppose int x = 500;
And int y =10;
Suppose address of y is also 500;
My doubt is there any difference between the properties of value of x
and address of y which is 500.
Yes. You haven't completed the description of y, which also needs
to specify such things as memory block, whether or not actually in
memory (may be on disk, and swapped out, for example), etc. etc.
POINTERS ARE NOT INTEGERS.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com

Aug 9 '07 #5

P: n/a

"somenath" <so*********@gmail.comwrote in message
news:11**********************@q3g2000prf.googlegro ups.com...
Hi All.

I would like to know the following information.

1)Is there any difference between the address and integer ?

For example suppose int x = 500;
And int y =10;
Suppose address of y is also 500;
My doubt is there any difference between the properties of value of x
and address of y which is 500.
On the notional van Neumann machine pointers are integers that index the
memory space. Most computers do work like that. But not all. Some processors
have segmented architectures. Some compilers carry around extra information
with pointers to help catch buffer overruns. Siome implement 8 bit bytes on
top of processors which are inherently 32 bit.

So it is not normally helpful to think of a pointer as an integer.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
Aug 9 '07 #6

P: n/a
Eric Sosman <Er*********@sun.comwrites:
[...]
Other respondents have explained that a pointer is
not an integer, by showing that an address is not an
integer. But the difference goes even deeper: a pointer
is not just an address.
[...]

Except that the standard tends to use the terms "pointer" and
"address" more or less interchangeably. For example, the unary '&'
operator yields the *address* of its operand.

The term "address" is also commonly used to refer to a raw machine
address (the difference is whether it simply refers to a location in
memory, or also has type information associated with it).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 9 '07 #7

P: n/a
Eric Sosman wrote:
somenath wrote On 08/09/07 10:12,:
>Hi All.

I would like to know the following information.

1)Is there any difference between the address and integer ?

For example suppose int x = 500;
And int y =10;
Suppose address of y is also 500;
My doubt is there any difference between the properties of value of x
and address of y which is 500.

Other respondents have explained that a pointer is
not an integer, by showing that an address is not an
integer. But the difference goes even deeper: a pointer
is not just an address. Contemplate this code fragment
for a while, and you'll understand why a pointer is more
than an address:

union { double d; int i; } u;
double *dp = &u.d;
int *ip = &u.i;

In this code, the two pointers dp and ip point to the
same memory location. Nonetheless, they are different.
What makes them different?
They have different type. They have identical value. They have identical
size (4). They cannot be distinguished from one another except by the
compiler. Why do you think they are different?

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Aug 9 '07 #8

P: n/a
Joe Wright <jo********@comcast.netwrites:
Eric Sosman wrote:
[...]
> Other respondents have explained that a pointer is
not an integer, by showing that an address is not an
integer. But the difference goes even deeper: a pointer
is not just an address. Contemplate this code fragment
for a while, and you'll understand why a pointer is more
than an address:
union { double d; int i; } u;
double *dp = &u.d;
int *ip = &u.i;
In this code, the two pointers dp and ip point to the
same memory location. Nonetheless, they are different.
What makes them different?
They have different type. They have identical value. They have
identical size (4). They cannot be distinguished from one another
except by the compiler. Why do you think they are different?
You said it yourself: they have different type.

Furthermore, how do you know they have the same size, or that their
size is 4 bytes? I work on systems where they'd both have a size of 8
bytes, and it's entirely possible for their sizes to differ.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 9 '07 #9

P: n/a
Joe Wright wrote On 08/09/07 18:01,:
Eric Sosman wrote:
>>somenath wrote On 08/09/07 10:12,:
>>>Hi All.

I would like to know the following information.

1)Is there any difference between the address and integer ?

For example suppose int x = 500;
And int y =10;
Suppose address of y is also 500;
My doubt is there any difference between the properties of value of x
and address of y which is 500.

Other respondents have explained that a pointer is
not an integer, by showing that an address is not an
integer. But the difference goes even deeper: a pointer
is not just an address. Contemplate this code fragment
for a while, and you'll understand why a pointer is more
than an address:

union { double d; int i; } u;
double *dp = &u.d;
int *ip = &u.i;

In this code, the two pointers dp and ip point to the
same memory location. Nonetheless, they are different.
What makes them different?

They have different type. They have identical value. They have identical
size (4). They cannot be distinguished from one another except by the
compiler. Why do you think they are different?
Because `array[*ip]' might work (given a suitable
value in `u.i') while `array[*dp]' won't even compile.

Because `ip = dp' won't even compile.

Because `sizeof *ip != sizeof *dp' (probably).

Because `*dp = DBL_MAX' is legal but `*ip = DBL_MAX'
probably invokes undefined behavior.

Because `if ((*dp = DBL_MIN))' branches oppositely
to `if ((*ip = DBL_MIN))'.

Because `printf ("%f\n", *dp)' works (with a suitable
value in `u.d') but `printf ("%f\n", *ip)' invokes undefined
behavior, always.

Because we've moved beyond B.

--
Er*********@sun.com
Aug 9 '07 #10

P: n/a
Eric Sosman wrote:
Joe Wright wrote On 08/09/07 18:01,:
>Eric Sosman wrote:
>>somenath wrote On 08/09/07 10:12,:

Hi All.

I would like to know the following information.

1)Is there any difference between the address and integer ?

For example suppose int x = 500;
And int y =10;
Suppose address of y is also 500;
My doubt is there any difference between the properties of value of x
and address of y which is 500.
Other respondents have explained that a pointer is
not an integer, by showing that an address is not an
integer. But the difference goes even deeper: a pointer
is not just an address. Contemplate this code fragment
for a while, and you'll understand why a pointer is more
than an address:

union { double d; int i; } u;
double *dp = &u.d;
int *ip = &u.i;

In this code, the two pointers dp and ip point to the
same memory location. Nonetheless, they are different.
What makes them different?
They have different type. They have identical value. They have identical
size (4). They cannot be distinguished from one another except by the
compiler. Why do you think they are different?

Because `array[*ip]' might work (given a suitable
value in `u.i') while `array[*dp]' won't even compile.

Because `ip = dp' won't even compile.

Because `sizeof *ip != sizeof *dp' (probably).

Because `*dp = DBL_MAX' is legal but `*ip = DBL_MAX'
probably invokes undefined behavior.

Because `if ((*dp = DBL_MIN))' branches oppositely
to `if ((*ip = DBL_MIN))'.

Because `printf ("%f\n", *dp)' works (with a suitable
value in `u.d') but `printf ("%f\n", *ip)' invokes undefined
behavior, always.

Because we've moved beyond B.
Perhaps I was unclear. Consider please..

void *y, *z;
y = &u.d;
z = &u.i;

Now how shall we differentiate between y and z?

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Aug 10 '07 #11

P: n/a
Joe Wright wrote:
Eric Sosman wrote:
>Joe Wright wrote On 08/09/07 18:01,:
>>Eric Sosman wrote:

somenath wrote On 08/09/07 10:12,:

Hi All.
>
I would like to know the following information.
>
1)Is there any difference between the address and integer ?
>
For example suppose int x = 500;
And int y =10;
Suppose address of y is also 500;
My doubt is there any difference between the properties of value of x
and address of y which is 500.
Other respondents have explained that a pointer is
not an integer, by showing that an address is not an
integer. But the difference goes even deeper: a pointer
is not just an address. Contemplate this code fragment
for a while, and you'll understand why a pointer is more
than an address:

union { double d; int i; } u;
double *dp = &u.d;
int *ip = &u.i;

In this code, the two pointers dp and ip point to the
same memory location. Nonetheless, they are different.
What makes them different?

They have different type. They have identical value. They have
identical size (4). They cannot be distinguished from one another
except by the compiler. Why do you think they are different?

Because `array[*ip]' might work (given a suitable
value in `u.i') while `array[*dp]' won't even compile.

Because `ip = dp' won't even compile.

Because `sizeof *ip != sizeof *dp' (probably).

Because `*dp = DBL_MAX' is legal but `*ip = DBL_MAX'
probably invokes undefined behavior.

Because `if ((*dp = DBL_MIN))' branches oppositely
to `if ((*ip = DBL_MIN))'.

Because `printf ("%f\n", *dp)' works (with a suitable
value in `u.d') but `printf ("%f\n", *ip)' invokes undefined
behavior, always.

Because we've moved beyond B.
Perhaps I was unclear. Consider please..

void *y, *z;
y = &u.d;
z = &u.i;

Now how shall we differentiate between y and z?
They are the same. So are `&u.i' and `(int*)&u'.
But `y' and `z' are different from both `dp' and `ip'.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Aug 10 '07 #12

P: n/a
Joe Wright wrote:
Eric Sosman wrote:
.... snip ...
>>
union { double d; int i; } u;
double *dp = &u.d;
int *ip = &u.i;

In this code, the two pointers dp and ip point to the
same memory location. Nonetheless, they are different.
What makes them different?

They have different type. They have identical value. They have
identical size (4). They cannot be distinguished from one another
except by the compiler. Why do you think they are different?
And what gives you the right to make those statements? The
addresses may specify all sorts of added information, such as
memory bank, disk drive (for cached), type of data referenced,
etc. You don't know how the system organizer has arranged all
that.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Aug 10 '07 #13

P: n/a
Keith Thompson wrote:
Eric Sosman <Er*********@sun.comwrites:
[...]
> Other respondents have explained that a pointer is
not an integer, by showing that an address is not an
integer. But the difference goes even deeper: a pointer
is not just an address.
[...]

Except that the standard tends to use the terms "pointer" and
"address" more or less interchangeably. For example, the unary '&'
operator yields the *address* of its operand.

The term "address" is also commonly used to refer to a raw machine
address (the difference is whether it simply refers to a location in
memory, or also has type information associated with it).
Wrong nomenclature IMO. An address is not necessarily an integer.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Aug 10 '07 #14

P: n/a
CBFalconer <cb********@yahoo.comwrites:
Keith Thompson wrote:
>Eric Sosman <Er*********@sun.comwrites:
[...]
>> Other respondents have explained that a pointer is
not an integer, by showing that an address is not an
integer. But the difference goes even deeper: a pointer
is not just an address.
[...]

Except that the standard tends to use the terms "pointer" and
"address" more or less interchangeably. For example, the unary '&'
operator yields the *address* of its operand.

The term "address" is also commonly used to refer to a raw machine
address (the difference is whether it simply refers to a location in
memory, or also has type information associated with it).

Wrong nomenclature IMO. An address is not necessarily an integer.
Um, where did I mention integers? What I'm calling a "raw machine
address" refers to a location in memory. Something integer-like is a
common way to implement that, but it's not the only way (except that
it's almost certainly made of bits).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 10 '07 #15

P: n/a
CBFalconer said:
Joe Wright wrote:
>Eric Sosman wrote:
... snip ...
>>>
union { double d; int i; } u;
double *dp = &u.d;
int *ip = &u.i;

In this code, the two pointers dp and ip point to the
same memory location. Nonetheless, they are different.
What makes them different?

They have different type. They have identical value. They have
identical size (4). They cannot be distinguished from one another
except by the compiler. Why do you think they are different?

And what gives you the right to make those statements? The
addresses may specify all sorts of added information, such as
memory bank, disk drive (for cached), type of data referenced,
etc. You don't know how the system organizer has arranged all
that.
All true, but whatever information the system must store in dp to enable
it to locate u.d must *also* be stored in ip to enable it to locate u.i
- so as far as I can see, Joe Wright has a point.

The most contentious part of his statement is that the two pointers
"have identical value" - I see value as being fundamentally bound up
with type, so I don't quite agree that two pointers of different type
can have the same value. Nevertheless I accept that they both point to
the same bunch of bits.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Aug 10 '07 #16

P: n/a
Joe Wright wrote:
Eric Sosman wrote:
>Joe Wright wrote On 08/09/07 18:01,:
>>Eric Sosman wrote:
somenath wrote On 08/09/07 10:12,:
.... snip ...
>>>>
union { double d; int i; } u;
double *dp = &u.d;
int *ip = &u.i;
.... snip ...
>
Perhaps I was unclear. Consider please..

void *y, *z;
y = &u.d;
z = &u.i;

Now how shall we differentiate between y and z?
y is a pointer to a double. z is a pointer to an int. Or rather,
they are such pointers converted to void*, and can only be
accurately converted back to the original types. QED.

For example,

dp = z; <or ip = y;

are both invalid statements.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com

Aug 10 '07 #17

This discussion thread is closed

Replies have been disabled for this discussion.