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

Re: pointer question

"Pavel A. Romashkin" <pavel.romashkin@noaa.gov> wrote in message
> Mark Hadfield wrote:
> > pro test, a
> >
> >     ; Do something with a
> >
> >     if not arg_present(a) then if ptr_valid(a) then ptr_free, a
> >
> > end
> I am sorry, I have not had my first cup of coffe yet. How is that
> supposed to work? If there is *no* argument present, *then* try to check
> if the missing argument is a pointer? What am I missing?

The question answered by ARG_PRESENT is not "Is this argument present", it
is "If I change this variable, will it be passed back to the caller?". So
the intention of the code in routine "test" was to see whether the calling
program holds a reference to variable a.

I have never used this in my own code, but tt seemed like a clever idea when
I suggested it. Jaco has pointed out the flaw: what if the caller holds the
pointer heap variable (say in an array) but chooses to pass it by value?

Mark Hadfield
m.hadfield@niwa.cri.nz  http://katipo.niwa.cri.nz/~hadfield
National Institute for Water and Atmospheric Research