I want to call my C or assembler function with a reference
parameter in a string. Why can't you just use the pointer returned
by _parc() to modify a string parameter?
Date: 23-Jul-91
From: Ted Means <73067.3332@compuserve.com>
Clipper 5.0 performed under-the-hood memory optimizations that
sometimes resulted in two strings being assigned the same pointer.
For example, if you did this:
X := "Some string"
Y := X
In all likelihood Clipper would simply make a copy of the pointer
rather than actually copying the string. It sounds great in
theory, because it saves memory. But problems arose when a C or
ASM routine attempted to modify X or Y by writing directly to the
assigned memory. Since the same pointer was assigned to two
different memvars, they both got changed, even though that was
not the intended effect.
So with the release of Clipper 5.01, Nantucket graciously
provided a method for accessing strings that is more convenient.
If you call __StorCLen with a null pointer *before* calling
__ParC, it warns Clipper that you plan to directly modify a
__ParC pointer and Clipper will take whatever steps are necessary
to make it safe to do so.
This gives the best of both worlds, in that Clipper can still
perform its memory optimizations, but C and ASM programmers get
the benefit of being able to directly modify strings. This is
all documented in the Release Notes, but briefly, if you need to
write directly to a string, use the following sequence:
1) Call __ParCLen to get the string's length.
2) Call __StorCLen with the length and a null pointer.
3) Call __ParC to get a pointer to the string. This
pointer will be safe to write to.
Writing directly to a __ParC pointer without using this method is
not sanctioned by Nantucket and is likely to cause problems.
Note, though, that if you don't need to write to the string you
can simply call __ParC by itself.