Re: Need help with user-written routine in SOR$

briggs_at_encompasserve.org
Date: 01/04/05


Date: 4 Jan 2005 15:09:21 -0600

In article <1104867989.968799.157870@c13g2000cwb.googlegroups.com>, hoefelmeyer@hotmail.com writes:
> Cool! The structure wrapper must be needed by VMS for some reason,
> then. I was just worried that it was something significant that was
> glossed over in the docs. Well, that makes it a lot easier for me! I'm
> very pleased to have my fears proved groundless. Thank you very much!
>
> A couple of other questions come to mind, with passing pointers -
> first, since ADRS1 and ADRS2 are pointers to my records, if I
> dereference them and modify non-key fields in them in my user_equal
> routine, it would indeed change the actual record, correct?

I think that would be invoking undefined behavior. There is no way
to know whether you are being handed an actual record or merely a
copy thereof.

> I know the
> answer in C, but am not sure in BASIC, i.e., is my function accessing a
> pointer to the actual record, as does C, or is it a pointer to a local
> copy of the record? The latter doesn't seem likely.

Since the record is being passed by reference, you know that you will
be modifying storage owned by the caller. But what the caller will
do with that modified storage is not documented.

It seems likely that the caller will, in fact, pass you a pointer to
his "live" copy of the record and that changes you make will actually
make it to the output file. Unless, of course, you are using a tag
sort, in which case the behavior might be different.

> And if I can, would doing so make the sort choke? I don't see why,
> because I'm not changing keys, but you never know. I'll check this out
> empirically.

The empirical approach is a good choice. Just beware of trusting the
results. Undocumented and unsupported behavior can change without notice.

        John Briggs



Relevant Pages

  • Re: CComPtr strange behaviour
    ... GetUIObjectOf takes an IUnknown* pointer it got from ... and tells the caller that it's really a pointer ...
    (microsoft.public.vc.atl)
  • Re: Should function argument be changed in function body?
    ... involved but even with something as simple as this it can make the caller ... handle an extra type that isn't natural to the problem. ... > You should try to avoid passing a non const pointer to a function unless ... It is probably more common for this reason for the status to be the return ...
    (comp.lang.c)
  • Allocating and returning new class in function
    ... from class method or operator). ... This would require caller to ... I would instantiate it dynamically and return pointer. ... should not rely on content of stack that is released when function is done. ...
    (comp.lang.cpp)
  • Re: [PATCH][RFC] Extend "memparse" to allow a NULL return pointer value.
    ... second parameter value if he has no interest in that returned value. ... stored in this pointer serves very important ... Caller must do this. ... If it returns `0' (zero), ...
    (Linux-Kernel)
  • Re: [RFC PATCH] rcu: introduce kfree_rcu()
    ... extern void rcu_init; ... the freeing then that is what the caller must be given. ... is the pointer that the memory chunk need to be freed. ... rcu kerneldoc is implemented in the .c file, ...
    (Linux-Kernel)