aruna <arunal2001@yah oo.co.in> scribbled the following:[color=blue]
> Why division/mulitiplication/addition of pointers are not
> allowed in C?[/color]
First define how it would work, and then we'll see why it should or
should not be allowed.
--
/-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The obvious mathematical breakthrough would be development of an easy way to
factor large prime numbers."
- Bill Gates
"aruna" <arunal2001@yah oo.co.in> wrote in message
news:a2efcaed.0 404230628.18b0d 5e1@posting.goo gle.com...[color=blue]
> Why division/mulitiplication/addition of pointers are not
> allowed in C?[/color]
Those operations have no obvious meaning, so there is no need.
Lew Pitcher wrote:
[color=blue]
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> aruna wrote:
>
> | Why division/mulitiplication/addition of pointers are not
> | allowed in C?
>
> A pointer can be considered to be the 'location' of a data item.
>
> Subtraction of one pointer from another gives you the 'distance' between
> two data items.
>
> What would addition of two pointers give you? (Hint: What does the
> addition of '12 Oak Lane' to '757 Main Street West' give you?)
>
> What would multiplication of two pointers give you? (Hint: What does the
> multiplication of '12 Oak Lane' with '757 Main Street West' give you?)
>
> What would division of two pointers give you? (Hint: What does the
> division of '12 Oak Lane' by '757 Main Street West' give you?)
>
> While pointer subtraction is meaningful, the other operations are not.
>
> - --
>
> Lew Pitcher, IT Consultant, Enterprise Application Architecture
> Enterprise Technology Solutions, TD Bank Financial Group[/color]
One can add a scalar quantity to a pointer to a new location.
For example, "Move 3 houses north of 12 Oak Lane", makes sense.
If two pointers can be subracted for a distance then a distance
should be added from one pointer to generate a new pointer value.
aruna wrote:[color=blue]
>
> Why division/mulitiplication/addition of pointers are not
> allowed in C?[/color]
Using right forefinger, point to nose. Using left forefinger,
point to right ear. Now define the product, sum, ratios of those
pointers.
--
Chuck F (cbfalconer@yah oo.com) (cbfalconer@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Thomas Matthews <Thomas_Matthew sSpitsOnSpamBot s@sbcglobal.net > scribbled the following:[color=blue]
> Lew Pitcher wrote:[color=green]
>> aruna wrote:
>> | Why division/mulitiplication/addition of pointers are not
>> | allowed in C?
>>
>> A pointer can be considered to be the 'location' of a data item.
>>
>> Subtraction of one pointer from another gives you the 'distance' between
>> two data items.
>>
>> What would addition of two pointers give you? (Hint: What does the
>> addition of '12 Oak Lane' to '757 Main Street West' give you?)
>>
>> What would multiplication of two pointers give you? (Hint: What does the
>> multiplication of '12 Oak Lane' with '757 Main Street West' give you?)
>>
>> What would division of two pointers give you? (Hint: What does the
>> division of '12 Oak Lane' by '757 Main Street West' give you?)
>>
>> While pointer subtraction is meaningful, the other operations are not.[/color][/color]
[color=blue]
> One can add a scalar quantity to a pointer to a new location.
> For example, "Move 3 houses north of 12 Oak Lane", makes sense.[/color]
[color=blue]
> If two pointers can be subracted for a distance then a distance
> should be added from one pointer to generate a new pointer value.[/color]
Where did anyone mention a scalar quantity?
--
/-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"You could take his life and..."
- Mirja Tolsa
In <a2efcaed.04042 30628.18b0d5e1@ posting.google. com> arunal2001@yaho o.co.in (aruna) writes:
[color=blue]
>Why division/mulitiplication/addition of pointers are not
>allowed in C?[/color]
Try figuring out some *useful* semantics for these operations and you may
understand why.
Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Dan.Pop@ifh.de
"CBFalconer " <cbfalconer@yah oo.com> wrote in message
news:40893C86.7 E1AB484@yahoo.c om...[color=blue]
> aruna wrote:[color=green]
> >
> > Why division/mulitiplication/addition of pointers are not
> > allowed in C?[/color]
>
> Using right forefinger, point to nose. Using left forefinger,
> point to right ear. Now define the product, sum, ratios of those
> pointers.[/color]
This analogy is lost on me. If I subtract one of those pointers from the
other, then what body part would I be pointing to now?
Tim Hagan <no.spam@boeing .com.invalid> scribbled the following:[color=blue]
> "CBFalconer " <cbfalconer@yah oo.com> wrote in message
> news:40893C86.7 E1AB484@yahoo.c om...[color=green]
>> aruna wrote:[color=darkred]
>> > Why division/mulitiplication/addition of pointers are not
>> > allowed in C?[/color]
>>
>> Using right forefinger, point to nose. Using left forefinger,
>> point to right ear. Now define the product, sum, ratios of those
>> pointers.[/color][/color]
[color=blue]
> This analogy is lost on me. If I subtract one of those pointers from the
> other, then what body part would I be pointing to now?[/color]
None. But you have the distance between your nose and your right ear. C
works like that too. Now define the product, sum and ratio of those
pointers. Either in real-world or C terms.
Joona I Palaste wrote:
[...][color=blue][color=green]
> > This analogy is lost on me. If I subtract one of those pointers from the
> > other, then what body part would I be pointing to now?[/color]
>
> None. But you have the distance between your nose and your right ear. C
> works like that too. Now define the product, sum and ratio of those
> pointers. Either in real-world or C terms.[/color]
The closest thing I can come up with (in real-world, but not C) is
(ptr1+ptr2)/2 for the average. (ie: what is midway between your nose
and right ear.) Of course, this is really the average of two _points_
and not two _pointers_.
And, in C, this can be done (assuming that ptr1 and ptr2 are such that
their difference is defined) with "ptr1 + ( (ptr2-ptr1) / 2 )", which is
more meaningful in a sense. (ie: start here and go halfway to there.)
Addition / subtraction is definitely allowed, the reason being pointers
refer to address and you can back and forth in the memory space. (Say,
as in an array as the memory is allocated continuously ).
Multiplication / Division just does not make sense, as there is no
necessity for them logically in a given program.
HTH
aruna wrote:[color=blue]
> Why division/mulitiplication/addition of pointers are not
> allowed in C?[/color]
In article <a2efcaed.04042 30628.18b0d5e1@ posting.google. com>, arunal2001@yaho o.co.in (aruna) wrote:
[color=blue]
> Why division/mulitiplication/addition of pointers are not
> allowed in C?[/color]
aruna wrote:
[color=blue]
> Why division/mulitiplication/addition of pointers are not
> allowed in C?[/color]
Pointer values are addresses. As such they are similar to postal zip
codes or telephone numbers. Of what possible value would be the
division, multiplication or addition of two or more zip codes?
--
Joe Wright mailto:joewwrig ht@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Rakesh Kumar <dreamzlion_nos pamplz@yahoo.co m> scribbled the following:[color=blue]
> Addition / subtraction is definitely allowed, the reason being pointers
> refer to address and you can back and forth in the memory space. (Say,
> as in an array as the memory is allocated continuously ).[/color]
Addition of two pointers is not allowed, addition of a pointer and a
scalar is.
--
/-- Joona Palaste (palaste@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I am not very happy acting pleased whenever prominent scientists overmagnify
intellectual enlightenment."
- Anon
Comment