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:50:42 -0800 Organization: None to speak of Lines: 30 Message-ID: References: <87pojf5wk4.fsf@gmail.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+muxcacJseFSZLsvHcYJEi" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:MAfOyyUioRZCatIu2lSBVq2S8u0= sha1:DtExLcgRaHtTSLntyxQANEgazWI= Xref: csiph.com comp.lang.c:102329 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 Nope. > f(char *ptr){ > printf("%s - %u\n",ptr,(unsigned)sizeof(ptr)); > } > > f(char arr[10]){ > printf("%s - %u\n",arr,(unsigned)sizeof(arr)); > } arr is a pointer parameter that happens to be defined using array syntax. A parameter defined with an array type is adjusted to have a pointer type. The parameter definitions `char *ptr` and `char ptr[]` are equivalent, but calling that "array pointer equivalence" is misleading. [...] -- 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"