Re: Debug my program please.
- From: pa@xxxxxxxxxxxxxxxxxxxxx (Pierre Asselin)
- Date: Fri, 28 Oct 2005 15:28:44 +0000 (UTC)
Richard E Maine <nospam@xxxxxxxxxxxxx> wrote:
> Jugoslav Dujic <jdujic@xxxxxxxxx> wrote:
>> [ functions returning pointers ]
> 3) Not so much a gotcha as a "what is the benefit?" To me, the whole
> point of a function is that you can use it as part of an expression.
Good point, but pointer expressions do occur in practice. In
addition to Jugoslav's example where a returned pointer is passed
directly to another subprogram, there is
x= lookup(hashtable, key)%somefield
where lookup() returns a pointer to some type stored in the hashtable.
For the most part this would be a pointer to already existing data.
However I can see cases where it is convenient for lookup() to
allocate new data (with default values) when the key isn't found.
There is no memory leak because the new data is properly referenced
by the hashtable. A real-life example of mine went like
lookup(sparse_matrix, iglobal, jglobal)+= element_matrix(i,j)
but that was in C, where there is a "+=" operator :-)
--
pa at panix dot com
.
- References:
- Debug my program please.
- From: TC
- Re: Debug my program please.
- From: Richard E Maine
- Re: Debug my program please.
- From: Richard E Maine
- Debug my program please.
- Prev by Date: Re: Coupling Fortran Code with Simulink
- Next by Date: Re: memory not freed up?
- Previous by thread: Re: Debug my program please.
- Next by thread: Re: Debug my program please.
- Index(es):
Relevant Pages
|