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: Tue, 16 Aug 2016 14:03:06 -0700 Organization: None to speak of Lines: 71 Message-ID: References: <4628cd2d-9333-4be6-943a-eb593c5c4c12@googlegroups.com> <1c54e0e1-74f5-42d2-856b-7854a21028fc@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="6553"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Y1yXhQcQY51xL7IQuYhNb" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:K/CmpOCWV2Yu6iWVB2EL8l+/HE4= sha1:1yZxr/URzO/qhh4V1pkYjmuV4lE= Xref: csiph.com comp.lang.c:92340 supercat@casperkitty.com writes: > On Tuesday, August 16, 2016 at 1:06:20 PM UTC-5, Keith Thompson wrote: >> already5chosen writes: >> > The sentence "C arrays and pointers are the same thing" is incorrect >> > in fine details. >> >> It is incorrect in both fine details and overall concept. > > Is there any difference between array-type rvalues and pointer-type rvalues? Please (re-)read N1570 6.3.2.1. The C standard doesn't use the term "rvalue" except in one footnote, in 6.3.2.1. After explaining the meaning of "lvalue", it says: What is sometimes called "rvalue" is in this International Standard described as the "value of an expression". > Array-type lvalues behave nothing like pointer-type lvalues, but as far as > I can tell, the result of an rvalue conversion on an array is a pointer to > the first element. What do you mean by "rvalue conversion"? If you're referring to "lvalue conversion", a term defined in 6.3.2.1p2, it doesn't apply to expressions of array type. Of course an expression of array type is, in most contexts, implicitly converted to a pointer to its first element. I just noticed something odd (and perhaps slightly sloppy) about the wording that specifies that conversion (6.3.2.1p3): Except when it is the operand of the sizeof operator, the _Alignof operator, or the unary & operator, or is a string literal used to initialize an array, an expression that has type "array of type" is converted to an expression with type "pointer to type" that points to the initial element of the array object and is not an lvalue. Normally a "conversion" is applied to a value (the result of evaluating an expression), yielding another value. Here the standard says that an *expression* is "converted" (to an expression with a different type). So it's not the kind of conversion that might be specified by a cast operator. This conversion takes place at compile time, and is conceptually similar to the way a parameter of array type is "adjusted" become a parameter of pointer type (N1570 6.3.7.3p7). Which means, I think, that given: int arr[10]; int *ptr = arr; the expression `arr` *is* of type `int*`, because of this "conversion" (adjustment?) that takes place at compile time. The other way to look at it (and the way I thought of it before now) is that `arr` is of type `int[10]`, and that `int[10]` (l)value is implicitly converted to `int*` -- but given the way 6.3.2.1 talks about converting *expressions* rather than *values* I don't think that interpretation holds up. The final result is the same. The only difference is in the abstract conceptual underpinnings that lead to that result. -- 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"