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


Groups > comp.lang.c > #170585 > unrolled thread

Why does the -> operator exist ?

Started bySpiros Bousbouras <spibou@gmail.com>
First post2023-06-27 09:12 +0000
Last post2023-06-28 14:16 -0700
Articles 10 on this page of 30 — 14 participants

Back to article view | Back to comp.lang.c


Contents

  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

Page 2 of 2 — ← Prev page 1 [2]


#171008

FromKeith Thompson <Keith.S.Thompson+u@gmail.com>
Date2023-07-20 19:49 -0700
Message-ID<874jlyq8re.fsf@nosuchdomain.example.com>
In reply to#171004
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>> [...] I would argue that using `->` rather than `.` when the
>> prefix is a pointer makes for more explicit code, which is a good
>> thing;  [...]
>
> More explicit is not always better.

No, it isn't.

If you had anything to say about this particular case (`->` being more
explicit than `.`, and whether it's better), this would have been a good
opportunity to say it.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

[toc] | [prev] | [next] | [standalone]


#171820

FromTim Rentsch <tr.17687@z991.linuxsc.com>
Date2023-08-08 05:49 -0700
Message-ID<86pm3xbswl.fsf@linuxsc.com>
In reply to#171008
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>
>>> [...] I would argue that using `->` rather than `.` when the
>>> prefix is a pointer makes for more explicit code, which is a
>>> good thing;  [...]
>>
>> More explicit is not always better.
>
> No, it isn't.
>
> If you had anything to say about this particular case (`->` being
> more explicit than `.`, and whether it's better), this would have
> been a good opportunity to say it.

In the particular case of using '.' instead of '->', more
explicit is not always better.

[toc] | [prev] | [next] | [standalone]


#171891

FromKeith Thompson <Keith.S.Thompson+u@gmail.com>
Date2023-08-08 16:33 -0700
Message-ID<877cq5qfc6.fsf@nosuchdomain.example.com>
In reply to#171820
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>>> [...] I would argue that using `->` rather than `.` when the
>>>> prefix is a pointer makes for more explicit code, which is a
>>>> good thing;  [...]
>>>
>>> More explicit is not always better.
>>
>> No, it isn't.
>>
>> If you had anything to say about this particular case (`->` being
>> more explicit than `.`, and whether it's better), this would have
>> been a good opportunity to say it.
>
> In the particular case of using '.' instead of '->', more
> explicit is not always better.

That's a useless statement.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

[toc] | [prev] | [next] | [standalone]


#172214

FromTim Rentsch <tr.17687@z991.linuxsc.com>
Date2023-08-14 04:34 -0700
Message-ID<86wmxx7t7l.fsf@linuxsc.com>
In reply to#171891
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>
>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>
>>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>>>
>>>>> [...] I would argue that using `->` rather than `.` when the
>>>>> prefix is a pointer makes for more explicit code, which is a
>>>>> good thing;  [...]
>>>>
>>>> More explicit is not always better.
>>>
>>> No, it isn't.
>>>
>>> If you had anything to say about this particular case (`->` being
>>> more explicit than `.`, and whether it's better), this would have
>>> been a good opportunity to say it.
>>
>> In the particular case of using '.' instead of '->', more
>> explicit is not always better.
>
> That's a useless statement.

No more useless than the statement from you that prompted
the discussion.

[toc] | [prev] | [next] | [standalone]


#172219 — I love it... (Was: Why does the -> operator exist ?)

Fromgazelle@shell.xmission.com (Kenny McCormack)
Date2023-08-14 12:41 +0000
SubjectI love it... (Was: Why does the -> operator exist ?)
Message-ID<ubd7dc$3i682$1@news.xmission.com>
In reply to#172214
In article <86wmxx7t7l.fsf@linuxsc.com>,
Tim Rentsch  <tr.17687@z991.linuxsc.com> wrote:
...
>> That's a useless statement.
>
>No more useless than the statement from you that prompted
>the discussion.

I love it when CLC regs fight!

-- 
The randomly chosen signature file that would have appeared here is more than 4
lines long.  As such, it violates one or more Usenet RFCs.  In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
	http://user.xmission.com/~gazelle/Sigs/Infallibility

[toc] | [prev] | [next] | [standalone]


#172238

FromKeith Thompson <Keith.S.Thompson+u@gmail.com>
Date2023-08-14 15:10 -0700
Message-ID<87bkf9mg0y.fsf@nosuchdomain.example.com>
In reply to#172214
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>>>>> [...] I would argue that using `->` rather than `.` when the
>>>>>> prefix is a pointer makes for more explicit code, which is a
>>>>>> good thing;  [...]
>>>>>
>>>>> More explicit is not always better.
>>>>
>>>> No, it isn't.
>>>>
>>>> If you had anything to say about this particular case (`->` being
>>>> more explicit than `.`, and whether it's better), this would have
>>>> been a good opportunity to say it.
>>>
>>> In the particular case of using '.' instead of '->', more
>>> explicit is not always better.
>>
>> That's a useless statement.
>
> No more useless than the statement from you that prompted
> the discussion.

My original statement, quoted above, was that using `->` rather than
`.` is more explicit and that that's a good thing.  That was and
is my opinion, applicable only to that particular case.  I've used
languages that use `.` for both (where the prefix can be either
a structure or a pointer), and haven't had any particular problem
with that.  I have a preference, but not a strong preference.

If I see `foo->bar` in C code, I know that `foo` is a pointer
expression pointing to a struct or union.  If I see `foo.bar`, I
know that `foo` is an expression of struct or union type.  I know
that without looking for the declaration.  I sometimes find it
useful to be able to understand something about a code fragment
without having to understand 100% of the context.

You apparently think that was a useless statement.  You apparently
thought it was important enough to comment on it.

You refuted a claim that explicit is *always* better.  Of course
I never said that, nor do I believe it.

I tried to invite you to expand on your statement.  Perhaps you think
that dropping `->` and using `.` for both structs and pointers (and
unions and union pointers) would have been better.  Perhaps you have
good reasons for your preference, assuming it is your preference.
Perhaps an explanation of those preferences would have been useful
and interesting.  Heck, I might even agree with you.

Instead, you chose to respond several times, adding exactly nothing
useful to the discussion.  Perhaps you expected us to understand
what you were thinking without you saying it.  If so, that was an
unrealistic expectation.

Let's stop this.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

[toc] | [prev] | [next] | [standalone]


#172325

FromPhil Carmody <pc+usenet@asdf.org>
Date2023-08-15 23:00 +0300
Message-ID<877cpw3wjx.fsf@fatphil.org>
In reply to#172238
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>>>>>> [...] I would argue that using `->` rather than `.` when the
>>>>>>> prefix is a pointer makes for more explicit code, which is a
>>>>>>> good thing;  [...]
>>>>>>
>>>>>> More explicit is not always better.
>>>>>
>>>>> No, it isn't.
>>>>>
>>>>> If you had anything to say about this particular case (`->` being
>>>>> more explicit than `.`, and whether it's better), this would have
>>>>> been a good opportunity to say it.
>>>>
>>>> In the particular case of using '.' instead of '->', more
>>>> explicit is not always better.
>>>
>>> That's a useless statement.
>>
>> No more useless than the statement from you that prompted
>> the discussion.
>
> My original statement, quoted above, was that using `->` rather than
> `.` is more explicit and that that's a good thing.  That was and
> is my opinion, applicable only to that particular case.  I've used
> languages that use `.` for both (where the prefix can be either
> a structure or a pointer), and haven't had any particular problem
> with that.  I have a preference, but not a strong preference.
>
> If I see `foo->bar` in C code, I know that `foo` is a pointer
> expression pointing to a struct or union.  If I see `foo.bar`, I
> know that `foo` is an expression of struct or union type.  I know
> that without looking for the declaration.  I sometimes find it
> useful to be able to understand something about a code fragment
> without having to understand 100% of the context.
>
> You apparently think that was a useless statement.  You apparently
> thought it was important enough to comment on it.
>
> You refuted a claim that explicit is *always* better.  Of course
> I never said that, nor do I believe it.
>
> I tried to invite you to expand on your statement.  Perhaps you think
> that dropping `->` and using `.` for both structs and pointers (and
> unions and union pointers) would have been better.  Perhaps you have
> good reasons for your preference, assuming it is your preference.
> Perhaps an explanation of those preferences would have been useful
> and interesting.  Heck, I might even agree with you.

If I see:
  foo->x *= 2;
  frob(foo);
I don't even twitch. However, if I see:
  foo.x *= 2;
  frob(foo);
I begin to worry - how much of a structure am I filling the stack with,
or is frob just a harmless macro, or what. I immediately need to know
more.

So I'm definitely in team keep-em-different.

Phil
-- 
We are no longer hunters and nomads. No longer awed and frightened, as we have
gained some understanding of the world in which we live. As such, we can cast
aside childish remnants from the dawn of our civilization.
-- NotSanguine on SoylentNews, after Eugen Weber in /The Western Tradition/

[toc] | [prev] | [next] | [standalone]


#172371

FromTim Rentsch <tr.17687@z991.linuxsc.com>
Date2023-08-16 05:29 -0700
Message-ID<86zg2r5fxn.fsf@linuxsc.com>
In reply to#172238
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>
>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>
>>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>>>
>>>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>>>
>>>>>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>>>>>
>>>>>>> [...] I would argue that using `->` rather than `.` when the
>>>>>>> prefix is a pointer makes for more explicit code, which is a
>>>>>>> good thing;  [...]
>>>>>>
>>>>>> More explicit is not always better.
>>>>>
>>>>> No, it isn't.
>>>>>
>>>>> If you had anything to say about this particular case (`->` being
>>>>> more explicit than `.`, and whether it's better), this would have
>>>>> been a good opportunity to say it.
>>>>
>>>> In the particular case of using '.' instead of '->', more
>>>> explicit is not always better.
>>>
>>> That's a useless statement.
>>
>> No more useless than the statement from you that prompted
>> the discussion.
>
> My original statement, quoted above, was that using `->` rather
> than `.` is more explicit and that that's a good thing.  That was
> and is my opinion, applicable only to that particular case.  I've
> used languages that use `.` for both (where the prefix can be
> either a structure or a pointer), and haven't had any particular
> problem with that.  I have a preference, but not a strong
> preference.
>
> If I see `foo->bar` in C code, I know that `foo` is a pointer
> expression pointing to a struct or union.  If I see `foo.bar`, I
> know that `foo` is an expression of struct or union type.  I know
> that without looking for the declaration.  I sometimes find it
> useful to be able to understand something about a code fragment
> without having to understand 100% of the context.
>
> You apparently think that was a useless statement.  You apparently
> thought it was important enough to comment on it.

I didn't say your statement was useless.  I said only that
my statement is no more useless than yours.

> You refuted a claim that explicit is *always* better.  Of course I
> never said that, nor do I believe it.

I was not refuting, nor was I trying to refute, any such claim.
I was merely responding to a statement of your opinion, giving
a statement of my own opinion.

> I tried to invite you to expand on your statement.  Perhaps you
> think that dropping `->` and using `.` for both structs and
> pointers (and unions and union pointers) would have been better.
> Perhaps you have good reasons for your preference, assuming it is
> your preference.  Perhaps an explanation of those preferences
> would have been useful and interesting.  Heck, I might even agree
> with you.

You asked if I had anything to say about this particular case.
I did that.

> Instead, you chose to respond several times,

This statement mischaracterizes my postings.  I responded once to
your implicit question about a more specific statement.  I
responded later to your one-line posting saying that my response
was a useless statement.  In both cases I was responding to what
was said in the immediately previous posting.

> adding exactly
> nothing useful to the discussion.  Perhaps you expected us to
> understand what you were thinking without you saying it.  If so,
> that was an unrealistic expectation.

It would be good for you to learn that just because you want
something doesn't mean that other people want it.

> Let's stop this.

Feel free to stop at any time.  If there are no responses to my
comments here I'm not inclined to continue.

[toc] | [prev] | [next] | [standalone]


#171059

FromKaz Kylheku <864-117-4973@kylheku.com>
Date2023-07-22 05:39 +0000
Message-ID<20230721223748.150@kylheku.com>
In reply to#171004
On 2023-07-21, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>
>> [...] I would argue that using `->` rather than `.` when the
>> prefix is a pointer makes for more explicit code, which is a good
>> thing;  [...]
>
> More explicit is not always better.

There is good explicit and bad explicit.

Good implicit and bad implicit, likewise.

E.g. strtok implicitly using a global variable is not so hot.

"continue;" branching to an implicit top-of-loop label is fairly decent.


-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

[toc] | [prev] | [next] | [standalone]


#170603 — Re: Why does the -> operator exist ?

FromAndrey Tarasevich <andreytarasevich@hotmail.com>
Date2023-06-28 14:16 -0700
SubjectRe: Why does the -> operator exist ?
Message-ID<u7i809$1sa5s$1@dont-email.me>
In reply to#170585
On 6/27/2023 2:12 AM, Spiros Bousbouras wrote:
> 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 ?

The original `->` operator first introduced in nascent C language was 
not a mere shorthand for `*`-then-`.` combination. It supported its own 
exclusive functionality, like dereferencing integer addresses.

At the same time '.' operator also worked completely differently from 
how it works in modern C: filed names were not associated with specific 
struct types and `.` could be applied to an lvalue of any type.

So, in nascent C you could write code like the following

   struct S
   {
     int a, b;
     /* Field `b` is offset `sizeof(int)` bytes from
        the beginning of the struct */
   };

   int main()
   {
     int addr = 0x1234;

     addr->b = 42;
     /* Assign `42` to an `int` at address `0x1234+sizeof(int)` */

     addr.b = 42;
     /* Assign `42` to an `int` at address `&i+sizeof(int)` */

     ...
   }

So, yes, back then there was obvious ambiguity between the two. That's 
why it existed.

Later the language changed. Field names became tightly associated with 
their struct types, while `->` turned into the exact equivalent for 
`*`-then-`.` combination.

-- 
Best regards,
Andrey

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.c


csiph-web