Re: Pointers in C
- From: "Clark S. Cox III" <clarkcox3@xxxxxxxxx>
- Date: Thu, 22 Feb 2007 07:58:59 -0500
rafalp wrote:
Clark S. Cox III wrote:
I'm not making anywhere the assumption that they are adjacent. My point
was to explain to the OP that for two given objects o1, o2 of the
same type
&o1 - &o2 := (addressof(o1) - addressof(o2)) / sizeof(objects)
That's all.
Even that isn't guaranteed.
(&o1 - &o2) could be (42) and ((char*)&o1 - (char*)&o2) could be
('bananas'). Subtracting pointers to two objects that aren't part of
some other object (i.e. array, structure, union, etc.) is undefined.
I don't understand what you mean. (&o1 - &o2) and ((char*)&o1 -
(char*)&o2) give different results even if o1 and o2 are the part of the
same array unless sizeof(o1) == sizeof(char).
If they are *not* part of the same array, there are no restrictions on
what either subtraction could yield, nor is there any guarantee that the
two results are related in any way (hence the "42" and "'bananas'").
--
Clark S. Cox III
clarkcox3@xxxxxxxxx
.
- References:
- Pointers in C
- From: Praveen
- Re: Pointers in C
- From: rafalp
- Re: Pointers in C
- From: Richard Heathfield
- Re: Pointers in C
- From: rafalp
- Re: Pointers in C
- From: Richard Heathfield
- Re: Pointers in C
- From: rafalp
- Re: Pointers in C
- From: santosh
- Re: Pointers in C
- From: rafalp
- Re: Pointers in C
- From: Clark S. Cox III
- Re: Pointers in C
- From: rafalp
- Pointers in C
- Prev by Date: Re: Pointers in C
- Next by Date: about far & near keywords in c
- Previous by thread: Re: Pointers in C
- Next by thread: Re: Pointers in C
- Index(es):
Relevant Pages
|