MESSAGE
DATE | 2016-12-10 |
FROM | Ruben Safir
|
SUBJECT | Re: [Learn] references to pointers
|
From learn-bounces-at-nylxs.com Sat Dec 10 22:53:12 2016 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: from www.mrbrklyn.com (www.mrbrklyn.com [96.57.23.82]) by mrbrklyn.com (Postfix) with ESMTP id A0346161312; Sat, 10 Dec 2016 22:53:12 -0500 (EST) X-Original-To: learn-at-nylxs.com Delivered-To: learn-at-nylxs.com Received: from [10.0.0.62] (flatbush.mrbrklyn.com [10.0.0.62]) by mrbrklyn.com (Postfix) with ESMTP id 6933B160E77 for ; Sat, 10 Dec 2016 22:53:09 -0500 (EST) To: learn-at-nylxs.com References: From: Ruben Safir Message-ID: <99cb6724-e423-c9f4-0290-79a7964e5699-at-mrbrklyn.com> Date: Sat, 10 Dec 2016 22:53:09 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.0 MIME-Version: 1.0 In-Reply-To: Subject: Re: [Learn] references to pointers X-BeenThere: learn-at-nylxs.com X-Mailman-Version: 2.1.17 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: learn-bounces-at-nylxs.com Sender: "Learn"
[This mail was also posted to comp.lang.c++.]
On Sat, 10 Dec 2016 18:29:06 -0800, Barry Schwarz wrote:
>>What is the difference between these two statements >> >> unsigned char * &index(unsigned char * value){ >> index_ = value; >> return index_; >> }; >> >>and without the reference: >> >> unsigned char * index(unsigned char * value){ >> index_ = value; >> return index_; >> }; > > After you fix the errors so that the functions can compile cleanly: > > The first invokes undefined behavior (or is it a constraint > violation) because it returns a reference to an object that will > disappear as soon as the function ends. > > The second returns the value of that object and that will survive > the destruction of index_ with no problem.
right. index_ is actually a data member of the object which this function is a member of.
it points to a member of allocated memory which contains an image.
the second returns the address to a char within that memory which index_ points to.
The second one returns an lvalue reference of a pointer to char.
What practical difference is there in this case? -- So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998 http://www.mrbrklyn.com
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002 http://www.nylxs.com - Leadership Development in Free Software http://www2.mrbrklyn.com/resources - Unpublished Archive http://www.coinhangout.com - coins! http://www.brooklyn-living.com
Being so tracked is for FARM ANIMALS and and extermination camps, but incompatible with living as a free human being. -RI Safir 2013 _______________________________________________ Learn mailing list Learn-at-nylxs.com http://lists.mrbrklyn.com/mailman/listinfo/learn
|
|