Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: pointers |
| Date | 2016-10-24 13:16 -0700 |
| Organization | None to speak of |
| Message-ID | <lnshrla4et.fsf@kst-u.example.com> (permalink) |
| References | (8 earlier) <nulcl7$sr1$1@dont-email.me> <lneg35bsfq.fsf@kst-u.example.com> <nulfjf$qgb$1@dont-email.me> <ln60ohblkv.fsf@kst-u.example.com> <nulp42$nqg$1@dont-email.me> |
BartC <bc@freeuk.com> writes:
> On 24/10/2016 20:20, Keith Thompson wrote:
>> BartC <bc@freeuk.com> writes:
>>> On 24/10/2016 17:52, Keith Thompson wrote:
>>>> BartC <bc@freeuk.com> writes:
>>>>> And yes I can see this being used, even if it's just to illustrate an
>>>>> example like this (you'll need to imagine the spaces between &s):
>>>>>
>>>>> int **pointer;
>>>>>
>>>>> **pointer; // 3 net derefs (one is always implicit with
>>>>> // variables in HLLs); result: int
>>>>> &**pointer; // 2 net derefs; int* ( *pointer)
>>>>> &&**pointer; // 1 net deref; int** ( pointer)
>>>>> &&&**pointer; // 0 net derefs; int*** ( &pointer)
>>>>> &&&&**pointer; // -1 net derefs: error (&&pointer)
>>>>
>>>> So the only reason you can think of to use those constructs is to
>>>> illustrate them? That's hardly a good reason to add them to the
>>>> language.
>>>>
>>>> The unary & operator yields the address of its operand.
>>>
>>> What does that mean?
>>
>> The operand must be an lvalue, which means it's an expression that
>> designates an object. It yields the address of that object.
>
> But &**pointer yields the address of the int value designated by **pointer.
Yes.
> That address is itself stored in an object and can also be written as
> *pointer.
No, it's not stored in an object. Why do you think it is?
> So &**pointer and *pointer yield the same value, the same type, and the
> same object.
Same value, yes. Same type, yes. Same object, no. *pointer is an
lvalue that designates the object pointed to by `pointer`. &**pointer
is not an value; evaluating it yields the address of an object, but it
is not an lvalue and does not designate an object.
Similarly, given:
int n = 25;
the expressions `n` and `25` yield the same value and the same type, but
only one of them designates an object.
> Why then I can only put a & in front of *pointer, but not in front of
> &**pointer which is the same thing?
Because *pointer is an lvalue and &**pointer is not. Are you having
difficulty understanding this, believing it, or accepting it?
>> &**pointer is equivalent to *pointer,
>
> So you agree...
>
> except
>> that the constraints on the operators still apply and the result is not
>> an lvalue.
>
> ... then what IS the difference between the two? Is it just the C
> standard decided there ought to be a difference just for the hell of it?
>
>> Both **pointer and *pointer are lvalues. Where did you get the idea
>> that *pointer isn't an lvalue?
>
> What's &**pointer then?
Oh, come on, you can figure that out.
>> You seem to be inventing a principle that the unary * and & operators
>> should cancel each other out when combined in arbitrary ways. There is
>> no such principle in C.
>
> The trouble is, that makes sense, and leads to consistency and
> orthogonality. Doing anything else doesn't.
"A foolish consistency is the hobgoblin of little minds"
-- Ralph Waldo Emerson.
> I wouldn't be bothered so much if C insisted that & can only be followed
> by the name of an object. That's a reasonable simplification especially
> for 1970.
Again, the operand of & must be an lvalue, an expression that
(potentially) desigates an object. Restricting it to the "name of an
object" (do you mean a single identifier?) would be foolish. I have no
clue how 1970 is relevant.
> But since C appears to allow this:
>
> *&*&*&*&*&*&*&*&*&*&*&*&pointer=0;
>
> then why not more silliness!
Why more silliness? If you don't like the fact that
*&*&*&*&*&*&*&*&*&*&*&*&pointer=0;
is valid, what restriction would you have the language impose to ban it?
Should `- - - - - - - - - - - - - - - - 42` be illegal?
The operand of unary & must be an lvalue (or a function designator).
The answers to most your silly questions follow from that simple rule.
Finally, I would seriously appreciate an answer to the following.
Exactly what problem do you have with all this? Do you (a) not believe
me when I tell you what the standard actually says, or (b) not accept
that the standard *means* what it says, or (c) simply dislike what the
standard says?
--
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
pointers asetofsymbols@gmail.com - 2016-10-23 08:11 -0700
Re: pointers Richard Heathfield <rjh@cpax.org.uk> - 2016-10-23 16:26 +0100
Re: pointers asetofsymbols@gmail.com - 2016-10-23 10:35 -0700
Re: pointers Ike Naar <ike@iceland.freeshell.org> - 2016-10-23 17:47 +0000
Re: pointers asetofsymbols@gmail.com - 2016-10-25 12:55 -0700
Re: pointers "James R. Kuyper" <jameskuyper@verizon.net> - 2016-10-23 13:58 -0400
Re: pointers BartC <bc@freeuk.com> - 2016-10-24 00:55 +0100
Re: pointers Keith Thompson <kst-u@mib.org> - 2016-10-23 17:27 -0700
Re: pointers BartC <bc@freeuk.com> - 2016-10-24 11:53 +0100
Re: pointers supercat@casperkitty.com - 2016-10-24 07:29 -0700
Re: pointers Keith Thompson <kst-u@mib.org> - 2016-10-24 08:55 -0700
Re: pointers Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-24 14:02 -0700
Re: pointers Keith Thompson <kst-u@mib.org> - 2016-10-24 14:42 -0700
Re: pointers Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-25 08:56 -0700
Re: pointers Keith Thompson <kst-u@mib.org> - 2016-10-25 12:17 -0700
Re: pointers Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-26 06:37 -0700
Re: pointers Keith Thompson <kst-u@mib.org> - 2016-10-24 08:49 -0700
Re: pointers BartC <bc@freeuk.com> - 2016-10-24 17:25 +0100
Re: pointers Keith Thompson <kst-u@mib.org> - 2016-10-24 09:52 -0700
Re: pointers BartC <bc@freeuk.com> - 2016-10-24 18:15 +0100
Re: pointers Keith Thompson <kst-u@mib.org> - 2016-10-24 12:20 -0700
Re: pointers BartC <bc@freeuk.com> - 2016-10-24 20:58 +0100
Re: pointers Keith Thompson <kst-u@mib.org> - 2016-10-24 13:16 -0700
Re: pointers BartC <bc@freeuk.com> - 2016-10-24 23:53 +0100
Re: pointers Keith Thompson <kst-u@mib.org> - 2016-10-25 13:38 -0700
Re: pointers BartC <bc@freeuk.com> - 2016-10-25 23:06 +0100
Re: pointers Keith Thompson <kst-u@mib.org> - 2016-10-25 15:39 -0700
Re: pointers BartC <bc@freeuk.com> - 2016-10-26 00:26 +0100
Re: pointers Keith Thompson <kst-u@mib.org> - 2016-10-25 16:44 -0700
Re: pointers BartC <bc@freeuk.com> - 2016-10-26 01:02 +0100
Re: pointers Keith Thompson <kst-u@mib.org> - 2016-10-25 17:35 -0700
Re: pointers Ike Naar <ike@iceland.freeshell.org> - 2016-10-26 06:27 +0000
Re: pointers BartC <bc@freeuk.com> - 2016-10-26 12:47 +0100
Re: pointers Keith Thompson <kst-u@mib.org> - 2016-10-26 09:05 -0700
Re: pointers BartC <bc@freeuk.com> - 2016-10-26 18:46 +0100
Re: pointers supercat@casperkitty.com - 2016-10-26 11:44 -0700
Re: pointers BartC <bc@freeuk.com> - 2016-10-26 20:12 +0100
Re: pointers BartC <bc@freeuk.com> - 2016-10-26 20:30 +0100
Re: pointers supercat@casperkitty.com - 2016-10-26 13:02 -0700
Re: pointers Keith Thompson <kst-u@mib.org> - 2016-10-26 11:52 -0700
Re: pointers Ike Naar <ike@iceland.freeshell.org> - 2016-10-26 19:11 +0000
Re: pointers BartC <bc@freeuk.com> - 2016-10-26 21:25 +0100
Re: pointers "James R. Kuyper" <jameskuyper@verizon.net> - 2016-10-25 18:56 -0400
Re: pointers "James R. Kuyper" <jameskuyper@verizon.net> - 2016-10-25 19:12 -0400
Re: pointers Keith Thompson <kst-u@mib.org> - 2016-10-25 16:31 -0700
Re: pointers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-10-24 21:36 +0100
Re: pointers BartC <bc@freeuk.com> - 2016-10-25 16:54 +0100
Re: pointers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-10-25 19:09 +0100
Re: pointers supercat@casperkitty.com - 2016-10-24 11:33 -0700
Re: pointers Keith Thompson <kst-u@mib.org> - 2016-10-24 12:22 -0700
Re: pointers James Kuyper <jameskuyper@verizon.net> - 2016-10-24 10:23 -0400
Re: pointers "James R. Kuyper" <jameskuyper@verizon.net> - 2016-10-23 12:31 -0400
Re: pointers Richard Heathfield <rjh@cpax.org.uk> - 2016-10-23 17:38 +0100
Re: pointers Lorinczy Zsigmond <zsiga@nospam.for.me> - 2016-10-24 14:02 +0200
Re: pointers John Bode <jfbode1029@gmail.com> - 2016-10-24 13:34 -0700
csiph-web