Why isn't there a ->= operator? 
Author Message
 Why isn't there a ->= operator?

I just wondered why the pointer to structure member reference doesn't
have a compound assignment operator.

Whenever you write code that walks through a linked list you could use a
compound assignment operator. E.g.:

  i = i -> Next;

would become:

  i ->= Next;

I like the consistency this operator would provide with the other
operators +=, *= etc..

Keith



Sat, 21 Apr 2001 03:00:00 GMT  
 Why isn't there a ->= operator?

Quote:

> I just wondered why the pointer to structure member reference doesn't
> have a compound assignment operator.

My guess would be that it doesn't follow naturally from the other
operators.  The current assignment operators are all based on arithmetic
operators, and -> isn't an arithmetic operator.

--
Eric Amick
Columbia, MD



Sat, 21 Apr 2001 03:00:00 GMT  
 Why isn't there a ->= operator?

Quote:

>I just wondered why the pointer to structure member reference doesn't
>have a compound assignment operator.

>Whenever you write code that walks through a linked list you could use a
>compound assignment operator. E.g.:

>  i = i -> Next;

>would become:

>  i ->= Next;

>I like the consistency this operator would provide with the other
>operators +=, *= etc..

Can you imagine another realistical use for "your" operator?

Dan
--
Dan Pop
CERN, IT Division

Mail:  CERN - EP, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland



Sat, 21 Apr 2001 03:00:00 GMT  
 Why isn't there a ->= operator?


Quote:
>I just wondered why the pointer to structure member reference doesn't
>have a compound assignment operator.

>Whenever you write code that walks through a linked list you could use a
>compound assignment operator. E.g.:

>  i = i -> Next;

>would become:

>  i ->= Next;

>I like the consistency this operator would provide with the other
>operators +=, *= etc..

>Keith

all/most operators work on the basic types like int, short int etc.
which would not ring true for "your" operator.

and: what if 'i' does not contain a next? some ppl like to write pnext (or
so) ..

Ren



Sat, 21 Apr 2001 03:00:00 GMT  
 Why isn't there a ->= operator?

Quote:


>>I just wondered why the pointer to structure member reference doesn't
>>have a compound assignment operator.

>>Whenever you write code that walks through a linked list you could use a
>>compound assignment operator. E.g.:

>>  i = i -> Next;

>>would become:

>>  i ->= Next;

>>I like the consistency this operator would provide with the other
>>operators +=, *= etc..

But inconsistent with its closest related operator .

Is i ->= Next; more readable than i = i -> Next; ? I don't think so. This
isn't an arithmetic operation between two operands, it is an object
selection operation which I don't think can be thought of in the same
way.

Quote:
>all/most operators work on the basic types like int, short int etc.
>which would not ring true for "your" operator.

>and: what if 'i' does not contain a next? some ppl like to write pnext (or
>so) ..

That's not a problem, you would write  i ->= pnext;  or whatever.

--
-----------------------------------------


-----------------------------------------



Sun, 22 Apr 2001 03:00:00 GMT  
 Why isn't there a ->= operator?
[snip]

Quote:
>>>Whenever you write code that walks through a linked list you could use a
>>>compound assignment operator. E.g.:

>>>  i = i -> Next;

>>>would become:

>>>  i ->= Next;

>>>I like the consistency this operator would provide with the other
>>>operators +=, *= etc..

>But inconsistent with its closest related operator .

>Is i ->= Next; more readable than i = i -> Next; ? I don't think so. This
>isn't an arithmetic operation between two operands, it is an object
>selection operation which I don't think can be thought of in the same
>way.

>>all/most operators work on the basic types like int, short int etc.
>>which would not ring true for "your" operator.

>>and: what if 'i' does not contain a next? some ppl like to write pnext (or
>>so) ..

>That's not a problem, you would write  i ->= pnext;  or whatever.

The biggest problem I see is that we have no proof that we are using a
linked list at all.  And the i->= foo metaphor only makes sense of both i
and foo have the same object base.  But suppose that one (or both) of them
is void?  Is the operation valid or not?

I think this is clearly a case where the programmer needs to have a clear
intention.
--
Hypertext C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-FAQ ftp: ftp://rtfm.mit.edu, C-FAQ Book: ISBN 0-201-84519-9
Try "C Programming: A Modern Approach" ISBN 0-393-96945-2
Want Software?  Algorithms?  Pubs? http://www.infoseek.com



Sun, 22 Apr 2001 03:00:00 GMT  
 Why isn't there a ->= operator?

Quote:
> I just wondered why the pointer to structure member reference doesn't
> have a compound assignment operator.

> Whenever you write code that walks through a linked list you could use a
> compound assignment operator. E.g.:

>   i = i -> Next;

> would become:

>   i ->= Next;

> I like the consistency this operator would provide with the other
> operators +=, *= etc..

+=, *=, etc. (originally written =+, =*, but these forms are now obsolete
and incorrect) were introduced because this allowed the compiler to fit
into less memory on the computers around when the B and C languages were
being developed (Ritchie 1993, "The development of the C language",
available at http://plan9.bell-labs.com/cm/cs/who/dmr/index.html.) Those
computers had hardly any memory. +=, ++, etc. were primarily for the
benefit of the compiler-writer, not the programmer.

Perhaps operations of the form i = i->next are rarer than those of the
form i = i + 2, so the shortcut for the benefit of compilers would have
been less significant.

Since current systems on which compilers run tend to have plenty of
memory, a new operator of this sort strikes me as unlikely to be
introduced.

But, if you're keen, make a suggestion for the new C9x language standard.
See comp.lang.c. The period for public comment on the draft standard is
almost over.

P.S. where's "tardis.ed"? Sounds local. (Hope I'm not teaching my
grandmother to suck eggs, so to speak! - but maybe the historical stuff is
of general interest anyhow.)

Daniel Barker,
Institute of Cell and Molecular Biology,
Swann Building,
King's Buildings,
Mayfield Road,
Edinburgh
EH9 3JR
UK



Mon, 23 Apr 2001 03:00:00 GMT  
 Why isn't there a ->= operator?

Quote:



> >Whenever you write code that walks through a linked list you could use a
> >compound assignment operator. E.g.:

> >  i = i -> Next;

> >would become:

> >  i ->= Next;

> Can you imagine another realistical use for "your" operator?

Maybe we could use this as a shortcut for i ->= Next:

        i->->;    /* :) */

Similarly, the following would be used for i ->Prev:

        i<-<-;

Anyway,

        i ->= Next;

is not meaningful, since -> 'dereferences' something, it doesn't
'operate' upon something (as + does, for example).

        AriL
--
Humans may send email (if absolutely necessary) to the
obvious non-spam address.



Mon, 23 Apr 2001 03:00:00 GMT  
 Why isn't there a ->= operator?

Quote:

> But, if you're keen, make a suggestion for the new C9x language standard.
> See comp.lang.c.

That should probably read comp.std.c.

        AriL
--
Humans may send email (if absolutely necessary) to the
obvious non-spam address.



Mon, 23 Apr 2001 03:00:00 GMT  
 Why isn't there a ->= operator?


...

Quote:
>Anyway,

>        i ->= Next;

>is not meaningful, since -> 'dereferences' something, it doesn't
>'operate' upon something (as + does, for example).

-> is still classed as an operator. a += b is shorthand for a = a + b (except
that if a is an expression with side-effects they are only evaluated once).
So i ->= Next would mean i = i -> Next (with similar issues
about side-effects) which is certainly meaningful. Whether such an operator
is desirable in the language is another matter however.

--
-----------------------------------------


-----------------------------------------



Tue, 24 Apr 2001 03:00:00 GMT  
 Why isn't there a ->= operator?


...

Quote:
>>>all/most operators work on the basic types like int, short int etc.
>>>which would not ring true for "your" operator.

>>>and: what if 'i' does not contain a next? some ppl like to write pnext (or
>>>so) ..

>>That's not a problem, you would write  i ->= pnext;  or whatever.

>The biggest problem I see is that we have no proof that we are using a
>linked list at all.  And the i->= foo metaphor only makes sense of both i
>and foo have the same object base.  But suppose that one (or both) of them
>is void?  Is the operation valid or not?

The simplest way to define it is i->= foo is valid when i = i->foo is valid
(except when i is an expression with side-effects where the first form may be
valid in cases where the second isn't). If i->foo has type void * then an
appropriate conversion would have to be performed.

Quote:
>I think this is clearly a case where the programmer needs to have a clear
>intention.

Certainly, I'm suggesting that a usable definition is possible, not that
this operator is necessarily desirable.

--
-----------------------------------------


-----------------------------------------



Thu, 26 Apr 2001 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. NULL isn't 0/0 isn't NULL

2. why isn't stdio full-duplex?

3. Top Left Icon - Why Isn't it Showing Up Correctly

4. Why isn't malloc necessary here?

5. HELP - why isn't ld working

6. why isn't there a strcasestr ?

7. Why isn't this working?

8. Why isn't there a logical XOR?

9. Why isn't one interface registered?

10. Why isn't ICollectionOnSTLImpl thread-safe?

11. Why isn't ATL complete?

12. Why isn't this legal C++

 

 
Powered by phpBB® Forum Software