Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #170604

Re: Why does the -> operator exist ?

From Kaz Kylheku <864-117-4973@kylheku.com>
Newsgroups comp.lang.c
Subject Re: Why does the -> operator exist ?
Date 2023-06-29 03:14 +0000
Organization A noiseless patient Spider
Message-ID <20230628200210.747@kylheku.com> (permalink)
References <trfLpf+N71iCzEwJm@bongo-ra.co> <87fs6cso8n.fsf@nosuchdomain.example.com> <5HB1OjHg4nJp9zZwI@bongo-ra.co>

Show all headers | View raw


On 2023-06-28, Spiros Bousbouras <spibou@gmail.com> wrote:
> On Tue, 27 Jun 2023 12:23:52 -0700
> Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>> Spiros Bousbouras <spibou@gmail.com> writes:
>> > I mean would it create an ambiguity if you could write  s.field
>> > both when  s  is a structure or union and when  s  is a pointer
>> > to a structure or union ?
>> 
>> There are languages that use the `.` operator for selecting a member
>> from either a structure or a pointer to a structure.  Since `.name` with
>> a pointer prefix has no other meaning, no ambiguity is introduced.  (Ada
>> is an example.)
>
> Interesting. I thought one of the design principles of Ada was to be
> explicit , with the idea that it helps reduce bugs.

Using two tokens for two different situations is no more or less
explicit than one.

a->b does two things: dereferences the pointer and selects a member;
if we change the spelling of the operator, that doesn't change
the semantics.

To be explicit, you have to use (*a).b so that this is done using
two separate operators: *a does the dereferencing to produce
a structure, whose member is then selected.

If the same operator is used, it's a case of overloading.

But Ada is not against overloading: it supports operator overloading!

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Why does the  ->  operator exist ? Spiros Bousbouras <spibou@gmail.com> - 2023-06-27 09:12 +0000
  Re: Why does the  ->  operator exist ? felix@palmen-it.de (Felix Palmen) - 2023-06-27 15:01 +0200
    Re: Why does the  ->  operator exist ? Spiros Bousbouras <spibou@gmail.com> - 2023-06-27 14:09 +0000
      Re: Why does the  ->  operator exist ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-06-27 15:56 +0100
  Re: Why does the -> operator exist ? Bart <bc@freeuk.com> - 2023-06-27 16:06 +0100
    Re: Why does the -> operator exist ? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-06-27 18:01 +0100
      Re: Why does the -> operator exist ? BGB <cr88192@gmail.com> - 2023-06-27 12:46 -0500
    Re: Why does the -> operator exist ? fir <profesor.fir@gmail.com> - 2023-08-09 00:08 -0700
      Re: Why does the -> operator exist ? fir <profesor.fir@gmail.com> - 2023-08-09 00:11 -0700
        Re: Why does the -> operator exist ? fir <profesor.fir@gmail.com> - 2023-08-09 00:23 -0700
  Re: Why does the  ->  operator exist ? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2023-06-27 15:13 +0000
  Re: Why does the  ->  operator exist ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-06-27 15:30 +0000
    Re: Why does the -> operator exist ? Bart <bc@freeuk.com> - 2023-06-27 17:05 +0100
      Re: Why does the -> operator exist ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-06-27 17:11 +0000
  Re: Why does the -> operator exist ? BGB <cr88192@gmail.com> - 2023-06-27 10:54 -0500
  Re: Why does the  ->  operator exist ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-06-27 12:23 -0700
    Re: Why does the  ->  operator exist ? Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2023-06-27 15:33 -0600
    Re: Why does the  ->  operator exist ? Spiros Bousbouras <spibou@gmail.com> - 2023-06-28 16:31 +0000
      Re: Why does the  ->  operator exist ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-06-29 03:14 +0000
    Re: Why does the  ->  operator exist ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-07-20 18:57 -0700
      Re: Why does the  ->  operator exist ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-07-20 19:49 -0700
        Re: Why does the  ->  operator exist ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-08-08 05:49 -0700
          Re: Why does the  ->  operator exist ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-08-08 16:33 -0700
            Re: Why does the  ->  operator exist ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-08-14 04:34 -0700
              I love it... (Was: Why does the  ->  operator exist ?) gazelle@shell.xmission.com (Kenny McCormack) - 2023-08-14 12:41 +0000
              Re: Why does the  ->  operator exist ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-08-14 15:10 -0700
                Re: Why does the  ->  operator exist ? Phil Carmody <pc+usenet@asdf.org> - 2023-08-15 23:00 +0300
                Re: Why does the  ->  operator exist ? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-08-16 05:29 -0700
      Re: Why does the  ->  operator exist ? Kaz Kylheku <864-117-4973@kylheku.com> - 2023-07-22 05:39 +0000
  Re: Why does the -> operator exist ? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2023-06-28 14:16 -0700

csiph-web