[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: object-model: Return by value, reference or pointer? (or something else?)

From: Hyrum K. Wright <hyrum_wright_at_mail.utexas.edu>
Date: Wed, 13 Oct 2010 14:51:39 -0500

On Wed, Oct 13, 2010 at 2:42 PM, Steinar Bang <sb_at_dod.no> wrote:
>>>>>> "Hyrum K. Wright" <hyrum_wright_at_mail.utexas.edu>:
>
>> Refcounting smartpointers are used to avoid duplication of the
>> underlying C structures, but they are completely private.  I've got
>> serious reservations about exposing that complexity in the external
>> object interfaces.  Given those reservations, the API would just
>> return a vanilla pointer, which leaves the caller the responsibility
>> of freeing it.
>
> Here I'm not following you.  You would hide the complexity of smart
> pointers, and would return plain pointers?

I would let the callers worry about the complexity of smart pointers
externally, rather than make an eternal interface decision based upon
them.

> Hm... the first I wouldn't worry about, and on the second I would go to
> great lenghts to make it hard to get at the plain pointers.

At this point, it's my turn to get confused. I'm speaking
specifically of cases where we return STL classes. Brane's earlier
suggestion to create an implicit bool conversion works fine for our
custom classes. The problem I'm trying to solve is "how does one
return the equivalent of '(const char *) NULL' in an std::string?"
It's a this point that pointers start coming into play, because a NULL
std::string * is quite feasible, whereas a NULL std::string isn't.

These strings, and their contents are copied from the internal values
used by the wrapper classes, so the actual C data would be completely
obscured. This is evidenced by the current (aforementioned) design.

-Hyrum
Received on 2010-10-13 21:52:17 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.