Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

references to pointers

27 views
Skip to first unread message

ruben safir

unread,
Dec 10, 2016, 8:17:00 PM12/10/16
to
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_;
};

Louis Krupp

unread,
Dec 10, 2016, 8:38:51 PM12/10/16
to
On Sat, 10 Dec 2016 20:16:52 -0500, ruben safir <ru...@mrbrklyn.com>
wrote:
They're not statements, they're function declarations, and it's hard
to say what the difference is since as far as I can tell neither one
compiles.

Do you have examples that do compile?

Louis

Barry Schwarz

unread,
Dec 10, 2016, 9:29:10 PM12/10/16
to
On Sat, 10 Dec 2016 20:16:52 -0500, ruben safir <ru...@mrbrklyn.com>
wrote:

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.

--
Remove del for email

Popping mad

unread,
Dec 10, 2016, 10:53:08 PM12/10/16
to le...@nylxs.com
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?

Alf P. Steinbach

unread,
Dec 10, 2016, 11:42:59 PM12/10/16
to
The “right” sounds like you're grading the answer on correctness, while
the "What practical difference?" sounds like you now want the answer to
yet another part of a homework assignment.

These signals are contradictory and both are baffling: you're not (yet)
competent to grade answers given here other than for clarity, and we do
not usually do people's homework in a way that could be successfully
submitted to the OP's teacher or professor. If someone answers a
homework question for real, then it's by accident. This is ¹a FAQ.

Not in the FAQ: it's been a long tradition in this group to sometimes
answer a homework question with technically correct but extremely
impractical and usually advanced code. These answers would reveal the
dishonest student as such to his or her professor or teacher. Just don't
ask for homework answers, please.


Cheers & hth.,

- Alf

PS: You probably wanted to write “second” and “first” rather than
“second” and “second”.

Links:
¹ <url: https://isocpp.org/wiki/faq/how-to-learn-cpp#help-with-homework>

ruben safir

unread,
Dec 11, 2016, 4:10:47 AM12/11/16
to
On 12/10/2016 11:39 PM, Alf P. Steinbach wrote:
> The “right” sounds like you're grading the answer on correctness, while
> the "What practical difference?" sounds like you now want the answer to
> yet another part of a homework assignment.

I don't post HW assignments Alf....
Boink again

ruben safir

unread,
Dec 11, 2016, 4:14:05 AM12/11/16
to
On 12/10/2016 11:39 PM, Alf P. Steinbach wrote:
> Not in the FAQ: it's been a long tradition in this group

really... Not that you represent the group, but is there any rules of
restricting replies to the topic?

Evidently not, which is why your posts are not of much value....ever.

I doubt you know the answer anyway. It would require deeper
understanding of the languages use and behaviors then you demonstrate
any knowledge in.


Alf P. Steinbach

unread,
Dec 11, 2016, 4:58:31 AM12/11/16
to
On 11.12.2016 10:13, ruben safir wrote:
> On 12/10/2016 11:39 PM, Alf P. Steinbach wrote:
>> Not in the FAQ: it's been a long tradition in this group
>
> really... Not that you represent the group, but is there any rules of
> restricting replies to the topic?

For clc++ there are only generally agreed on rules of conduct, e.g. as
in the FAQ, because this group lacks a charter.

The FAQ's requirement on questions was, and perhaps still is after the
migration to ISO CPP, that any question should be answerable with
reference only to the C++ standard. That was probably in order to limit
the number of questions concerning the Windows API, which once was a
major reason for the creation of the moderated sister group clc++m
(which does have a charter, but is now defunct).


> Evidently not, which is why your posts are not of much value....ever.
>
> I doubt you know the answer anyway. It would require deeper
> understanding of the languages use and behaviors then you demonstrate
> any knowledge in.

Personal attacs (which you're doing here), multiple nicks (as you're
using in this group), inane assertions and apparent evaluations of the
correctness of other's answers to your questions, as if you asked while
knowing an answer, shows the regulars that you're trolling.

That wastes your time, as well as ours.

Unless you're into negative sum games I suggest you change your ways,
e.g. ask some real questions, with copy and pasted code examples.

ruben safir

unread,
Dec 11, 2016, 5:26:10 AM12/11/16
to

>
> Unless you're into negative sum games I suggest you change your ways,
> e.g. ask some real questions, with copy and pasted code examples.

You have permission to not read my posts or to write back. Its too bad
thunderbird doesn't have a dev null. You are already /dev/nulled in the
other client.

Everything you post is a troll or a waste of time.

ruben safir

unread,
Dec 11, 2016, 5:32:44 AM12/11/16
to
On 12/11/2016 05:26 AM, ruben safir wrote:
> thunderbird doesn't have a dev null.


actually it does.... good.
0 new messages