Excerpts from the mail message of Ian Dash:
)
) <snip>....
) TM> int n;
) TM> getnumber(n);
) TM> printf( "The number is %d\n", n );
) </snip>
)
) no, but I fully expect to to be able to do this sort of thing
)
) char *mystring;
) mystring=getTimeAstring();
) printf("the time is %s",mystring);
Fine.
) /* or even this: getTimeAsString(mystring) - where the same happens,
) passing a pointer value=effectively by reference */
BZZZT! Reread what I wrote. This will never work!
) where the getTimeAsString function mallocs some space for the string
) and returns a pointer to the populated string.
To return a pointer to the allocated space you must pass the
_pointer_ by reference which means _a pointer to a pointer_
or C<char **>! C<char *> can be used to pass a C<char> by
reference, or even a buffer of C<char> by reference. But the
function can't change the _copy of the pointer_ that it gets
passed [via C<buf= malloc(n)>, for example] and have that
change effect the caller.
) The above code doesn't care that mystring may or may not be
) initialised...
BZZZT! Wrong again.
) I assumed this is what would be happening with the third
) party function BMODCRD -> DOH!
Write your own function that does what you think is possible
and see for yourself that it doesn't work!
--
Tye McQueen Nothing is obvious unless you are overlooking something
http://www.metronet.com/~tye/ (scripts, links, nothing fancy)