octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Passed by reference for an octave_value type storing an external res


From: Olaf Till
Subject: Re: Passed by reference for an octave_value type storing an external resource?
Date: Mon, 12 Nov 2012 17:38:02 +0100
User-agent: Mutt/1.5.20 (2009-06-14)

On Mon, Nov 12, 2012 at 04:39:04PM +0100, c. wrote:
> 
> On 12 Nov 2012, at 15:16, Olaf Till wrote:
> 
> > Without casting away const you cannot change the referenced
> > value. Without changing the referenced value, this technique is not
> > applicable to the issue I described. The issue is that pass by
> > reference is used to change an octave_value to make it keeping track
> > of the state (open/closed) of a resource (descriptor).
> > 
> > Olaf
> 
> Not sure your reasoning is correct here ...
> 
> if you have 
> 
> const myobject &mo;
> 
> and the field "str" in the class "myobject" is a pointer, 
> then, as you say, you cannot change the pointer "mo.str".
>  
> But you can still access the memory pointed to by it, i.e.
> you can change "*(mo.str)". [*]
> 
> Now what is the type of your "descriptor"? Is it a pointer?
> 
> c.

Its an integer in this case. In this and similar cases, using the said
strategy of containing the external resource (e.g. descriptor) within
a class derived from octave_base_value and hooking it into the .rep
field of an octave_value, one has to change something within .rep
(either the resource or an additional field) to keep track whether the
resource is open or closed.

You are right, if one makes such an additional field be a pointer and
allocates memory for it in the constructor, this could work. It would
be a way to circumvent const for this field without casting away const
for the whole object. However, I'd like to get a statement from JWE
what in detail his objections were against casting away const for the
said purpose. If they were only objections against exposing all the
fields to accidental writes by the cast, we could possibly use a
method which exposes only the needed field.

(Seemingly this thread has been inserted into a wrong one ...)

Olaf

-- 
public key id EAFE0591, e.g. on x-hkp://pool.sks-keyservers.net

Attachment: signature.asc
Description: Digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]