help-octave
[Top][All Lists]
Advanced

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

Re: variables `inheriting' values


From: Dupuis
Subject: Re: variables `inheriting' values
Date: Tue, 26 Jan 2010 02:08:30 -0800 (PST)



Mike111 wrote:
> 
> Hi All,
> 
> Is it possible to do define variables so they will `inherit' a value later
> on down the code, for example:
> 
> # a is still not defined
> b = a 
> # now a is set with a value, for example 
> a = sin( 1 )
> 
> so now b automatically `inherits' the value of a?.
> 
> 

A few years ago, a friend of mine, working as software developper in a bank,
told me three persons, including him, worked one week on a program code in C
to find a subtle bug in a program. It ran as follows:
- a variable was dynamically allocated, return value was a pointer;
- the pointer was duplicated in another variable;
- upon some error condition, a 'free' was called on the duplicated pointer,
which was set to NULL to indicate it became invalid;
- at the end of the function, a 'free' was performed on the original
pointer. Double free resulted in program hang.

Working safely on references implies for each object to keep track of the
numer of referers. This is implemented in C++ as 'smart pointer', but as
other commented, the ratio cost/benefit would not be very favorable.

OTOH, if you just need some placeholer, why not try:
mystruct.param = [];
if mystruct.param, then perform some operation; end
mystruct.param = [ 1 2 3];

Regards

Pascal
-- 
View this message in context: 
http://old.nabble.com/variables-%60inheriting%27-values-tp27292352p27320353.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

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