Using Pointer Returned from C Library in C++
<p>I am using a library developed in C (particularly: HTK). I've made a bit modifications to source and trying to get a pointer (to beginning of a linked list) from a function.
Not to go into too much detail; say I have a struct named OutType. In my C++ code I declare:
<strong>OutType* Out</strong>; and pass it to some function <strong>LName(....., OutType* Out)</strong>
Now, in the C library, LName takes parameter Out, and calles a function named SaveH where Out is the return value (<strong>Out=SaveH(...)</strong>) and in SaveH, Out is malloc'ed as <strong>OutType returnOut=(OutType*)malloc(1,sizeof(OutType));</strong>
As far as I see, Out is perfectly malloc'ed, and in LName function I can get the address of the memory area that was allocated. But when I return to my C++ code, where I call LName and pass Out as a parameter, that parameter always has 0 as the address.
If I leave everything same, but just change SaveH so that Out is not a return value, but a parameter as <strong>SaveH(....,OutType* Out)</strong> and alloc that value in C++ code before passing everything is fine.
Is it normal? Is there some problem with pointer allocated in C library, using in C++ code?
Thanks</p>
