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


Groups > comp.lang.c > #102332

Re: Access structure members via pointer to an array of structures

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Access structure members via pointer to an array of structures
Date 2017-01-22 07:54 -0800
Organization None to speak of
Message-ID <lnd1fff5uh.fsf@kst-u.example.com> (permalink)
References (2 earlier) <lntw8sf1hy.fsf@kst-u.example.com> <87pojf5wk4.fsf@gmail.com> <87pojfxs1h.fsf@bsb.me.uk> <o625rd$q8n$1@dont-email.me> <5c1625dc-4411-4220-b271-fcec7e45de9b@googlegroups.com>

Show all headers | View raw


Malcolm McLean <malcolm.mclean5@btinternet.com> writes:
> On Sunday, January 22, 2017 at 11:44:26 AM UTC, Bart wrote:
>> On 22/01/2017 11:17, Ben Bacarisse wrote:
>> > Gareth Owen <gwowen@gmail.com> writes:
>> >
>> >> Keith Thompson <kst-u@mib.org> writes:
>> >>
>> >>> Why would you tell someone trying to learn C about "array pointer
>> >>> equivalence"?  Arrays and pointers are not equivalent.
>> >>
>> >> They are occasionally
>> >
>> > "array pointer equivalence" does not suggest something occasional!
>> >
>> > There are a number of people here determined to avoid any explanation
>> > that simplified the issue.  Just refer to the "array to pointer
>> > conversion" and you are much closer to the truth without implying any
>> > false equivalence.
>> >
>> >> f(char *ptr){
>> >>   printf("%s - %u\n",ptr,(unsigned)sizeof(ptr));
>> >> }
>> >>
>> >> f(char arr[10]){
>> >>   printf("%s - %u\n",arr,(unsigned)sizeof(arr));
>> >> }
>> >
>> > There are no arrays in this code and I don't think Malcolm was talking
>> > about the interchangeability of * and [] syntax in a parameter list.
>> 
>> Maybe he was talking about the equivalence of 'years' and '*dat_years' 
>> here when used in most expression contexts:
>> 
>> data years[DATA_SIZE];               // [an array]
>> data *dat_years = years;             // [a pointer]

As you surely know by now, the `years` in the initializer is *converted*
(IMHO "adjusted" would have been a better word) to a pointer expression.

> Yes, that was in Alla's code.
> Someone who writes that probably doesn't understand array pointer
> equivalence. (So it's far to early to bring up a technical nit about
> the situations they are not equivalent).

Arrays and pointers are never equivalent.  Someone who writes "array
pointer equivalence" probably doesn't understand the relationship
between arrays and pointers.

Again, expressions of array type are *converted* to pointer type in most
contexts.  If they were "equivalent", no such conversion would be
necessary.

Stop spreading confusion and misinformation.  I'm sure Alla is able to
understand the actual language rules.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

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


Thread

Access structure members via pointer to an array of structures Alla _ <modelling.data@gmail.com> - 2017-01-21 02:00 -0800
  Re: Access structure members via pointer to an array of structures Alla _ <modelling.data@gmail.com> - 2017-01-21 02:08 -0800
    Re: Access structure members via pointer to an array of structures Chad <cdalten@gmail.com> - 2017-01-21 07:36 -0800
      Re: Access structure members via pointer to an array of structures Jerry Stuckle <jstucklex@attglobal.net> - 2017-01-21 11:13 -0500
    Re: Access structure members via pointer to an array of structures Jerry Stuckle <jstucklex@attglobal.net> - 2017-01-21 11:08 -0500
      Re: Access structure members via pointer to an array of structures Chad <cdalten@gmail.com> - 2017-01-21 09:09 -0800
        Re: Access structure members via pointer to an array of structures Jerry Stuckle <jstucklex@attglobal.net> - 2017-01-21 14:32 -0500
          Re: Access structure members via pointer to an array of structures Chad <cdalten@gmail.com> - 2017-01-21 12:57 -0800
            Re: Access structure members via pointer to an array of structures Chad <cdalten@gmail.com> - 2017-01-21 13:04 -0800
              Re: Access structure members via pointer to an array of structures Jerry Stuckle <jstucklex@attglobal.net> - 2017-01-21 17:59 -0500
              Re: Access structure members via pointer to an array of structures cross@spitfire.i.gajendra.net (Dan Cross) - 2017-01-22 14:02 +0000
                Re: Access structure members via pointer to an array of structures raltbos@xs4all.nl (Richard Bos) - 2017-01-22 14:17 +0000
                Re: Access structure members via pointer to an array of structures Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-30 05:25 -0800
            Re: Access structure members via pointer to an array of structures Jerry Stuckle <jstucklex@attglobal.net> - 2017-01-21 17:57 -0500
  Re: Access structure members via pointer to an array of structures Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-21 08:09 -0800
    Re: Access structure members via pointer to an array of structures Keith Thompson <kst-u@mib.org> - 2017-01-21 15:15 -0800
      Re: Access structure members via pointer to an array of structures Gareth Owen <gwowen@gmail.com> - 2017-01-22 08:27 +0000
        Re: Access structure members via pointer to an array of structures Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-22 11:17 +0000
          Re: Access structure members via pointer to an array of structures BartC <bc@freeuk.com> - 2017-01-22 11:44 +0000
            Re: Access structure members via pointer to an array of structures Malcolm McLean <malcolm.mclean5@btinternet.com> - 2017-01-22 04:27 -0800
              Re: Access structure members via pointer to an array of structures Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-22 13:32 +0000
              Re: Access structure members via pointer to an array of structures Keith Thompson <kst-u@mib.org> - 2017-01-22 07:54 -0800
            Re: Access structure members via pointer to an array of structures Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-01-22 13:31 +0000
          Re: Access structure members via pointer to an array of structures Gareth Owen <gwowen@gmail.com> - 2017-01-22 14:02 +0000
        Re: Access structure members via pointer to an array of structures Keith Thompson <kst-u@mib.org> - 2017-01-22 07:50 -0800
  Re: Access structure members via pointer to an array of structures Manfred <noname@invalid.add> - 2017-01-21 17:15 +0100
  Re: Access structure members via pointer to an array of structures David Brown <david.brown@hesbynett.no> - 2017-01-21 17:59 +0100
    Re: Access structure members via pointer to an array of structures Alla _ <modelling.data@gmail.com> - 2017-01-21 09:09 -0800
      Re: Access structure members via pointer to an array of structures Barry Schwarz <schwarzb@dqel.com> - 2017-01-21 09:27 -0800
        Re: Access structure members via pointer to an array of structures Alla _ <modelling.data@gmail.com> - 2017-01-21 09:30 -0800
    Re: Access structure members via pointer to an array of structures Alla _ <modelling.data@gmail.com> - 2017-01-21 09:25 -0800
  Re: Access structure members via pointer to an array of structures "Peter \"Shaggy\" Haywood" <phaywood@alphalink.com.au> - 2017-01-30 22:04 +1100

csiph-web