From owner-freebsd-questions Fri Apr 27 19:23:39 2001 Delivered-To: freebsd-questions@freebsd.org Received: from smtp2.cybersurf.net (smtp2.cybersurf.net [209.197.145.112]) by hub.freebsd.org (Postfix) with ESMTP id DCF5E37B42C for ; Fri, 27 Apr 2001 19:23:35 -0700 (PDT) (envelope-from 01031149@3web.net) Received: from 3web.net ([209.197.155.137]) by smtp2.cybersurf.net (Netscape Messaging Server 4.15) with SMTP id GCHDB900.RPS for ; Fri, 27 Apr 2001 20:23:33 -0600 Received: by 3web.net (EzMTS MTSAgent 1.22b Service) ; Fri, 27 Apr 01 20:22:43 -0600 for Received: from 3web.net (10.0.0.2) by 3web.net (EzMTS MTSSmtp 1.50 Service) ; Fri, 27 Apr 01 19:31:17 -0600 for Received: by mandy.rockingd.calgary.ab.ca (sSMTP sendmail emulation); Fri, 27 Apr 2001 19:30:51 +4200 Date: Fri, 27 Apr 2001 19:30:49 -0600 From: Duke Normandin <01031149@3web.net> To: Freebsd Questions Subject: OT - C Pointers Message-ID: <20010427193048.A70243@mandy.rockingd.calgary.ab.ca> Mail-Followup-To: Freebsd Questions Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i X-Envelope-Receiver: Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hi guys... Little OT if I might -- please! Ted Jensen, in his "A Tutorial on Pointers and Arrays in C" states, "But, back to using our new variable ptr. Suppose now that we want to store in ptr the "address" of our integer variable k. To do this we use the unary '&' operator and write: ptr = &k; The '&' operator's job is to: * retrieve the lvalue (address) of k, even though k is on the right hand side of the assignment operator '=', and * copy the address to the contents of our pointer ptr. Now, ptr is said to "point to" k." Ruurd Pels, in his "A Brief Tutorial on Pointers, Lvalues, & Rvalues" states: [some text snipped for brevity] " Definitions: rvalue the attribute of a variable that holds the address where that particular variable is stored. lvalue the attribute of a variable that holds the value of the variable. int v = 3; int* p; p = &v; <---- What the &-operator does is a modification of what happens at the left side of the assignment. Basically it tells the compiler not to use 'v'-s rvalue to obtain the address where the lvalue of 'v' is stored, but it tells it to use the rvalue of 'v' as the right hand side of the assignment. It then proceeds as normal, assigning the value obtained to the lvalue of p and storing that at the address contained in the rvalue of p. What we have now is a p with an rvalue that is equal to the address where p is stored, and an lvalue that is equal to the address where 'v' is stored. Bingo! We initialized a pointer. Conclusion: - The meaning of the symbol '&' in the context of a variable is "take-the-address-instead-of-the-value" " I'm confused!! In his "Definitions:" above, did Pels get rvalue and lvalue switched around? I ask because if you re-read what each states about the meaning of '&', they don't seem to jibe. Or, am I missing the obvious -- if there's such a thing with pointers? ;) Here's my take. Given: int i, k, *j; i = 3 k = i; <-- Case1 j = &i; <-- Case2 In Case1, lvalue of k -> the address of k rvalue of k -> the rvalue of i (via the lvalue of i) In Case2, lvalue of j -> the address of j rvalue of j -> the lvalue (address) of i So I lean towards Jensen's explanation, and the '&' means: DON'T use the lvalue of i to get the rvalue of i, to then do the assignment as normally would happen DO use the lvalue of i *only* for the assignment. So who's correct - Jensen and I; or Pels? And while we're *there* *j -> always refers to the rvalue of i TIA.... -- -duke Calgary, Alberta, Canada To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message