Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Access structure members via pointer to an array of structures Date: Sun, 22 Jan 2017 07:54:14 -0800 Organization: None to speak of Lines: 60 Message-ID: References: <87pojf5wk4.fsf@gmail.com> <87pojfxs1h.fsf@bsb.me.uk> <5c1625dc-4411-4220-b271-fcec7e45de9b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="888facdcfaaf0dacdc56e3b90fcf0c54"; logging-data="24027"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+s3Q2KdlJDMCZTFrdf45Ij" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:lbuIGH+9AmwXrs1g/2Bqa4hXY80= sha1:fP0U+micML0rWRQmRSlv7FHo1tg= Xref: csiph.com comp.lang.c:102332 Malcolm McLean 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 writes: >> > >> >> Keith Thompson 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 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"