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: Difference between these pointer syntaxes Date: Sat, 27 Aug 2016 12:07:10 -0700 Organization: None to speak of Lines: 31 Message-ID: References: <4628cd2d-9333-4be6-943a-eb593c5c4c12@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="28100"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX193bGiUtBdGYONa6jg89PHG" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:tffd/04t2rZ3HcHzQLwaAKzMpuo= sha1:dbAWqwTiXmyk69cXtKTmY3o6VXc= Xref: csiph.com comp.lang.c:92809 James Kuyper writes: [...] > C is built on the premise that only pointer values can be indexed or > dereferenced, with pointer[index] being exactly equivalent to > *(pointer+index), and that lvalues of array type automatically convert > into pointer values, allowing that rule to apply to them. There's no > internal inconsistency in that formulation, just an inconsistency > between that approach and the one you insist on following. [...] I've seen some people attempt to simplify the rules for when array expressions are "converted" to pointer expressions by saying that array *lvalues* are converted to pointer values. That's not accurate. For example, in `&array_object`, the subexpression `array_object` is clearly an lvalue (the operand of unary `&` has to be), but it's not converted. (I'm not sure that's what you're trying to do. If not, I'm just hijacking your statement to make a point.) In fact *all* expressions of array type are lvalues (I'm not quite 100% certain of that). You need to enumerate the three exceptions to determine when they are and are not converted to pointers. (One corner case is an array member of a struct or union value that is the result of a function call. C11 added the concept of "temporary lifetime" to account for this.) -- 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"