<gr********@hotmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
I'm a beginner to C++ (I've worked with Java) and I need a C program to
get an array created by another C++ program. How should I do this?
Would shared memory work to share the pointer? Can anyone give me an
example of code? Thanks.
It all depends what you mean by "share" ... if you want to pass the array to
a function written in C from within a C++ program, that is pretty easy. You
simply declare the C function within an extern C block (in the C++ program)
like so:
extern "C" {
// declaration matching C function-prototype
void my_cfunc(double *array);
}
and then you can call it with the C++ function. Since C and C++ use the same
memory layout for built-in arrays, this should "just work", barring index
overflow errors and the like. Of course you need to cross-link the object
code for the C++ and C elements, but that is straightforward with most
compilers .. check your docs.
OTOH, if what you want is to access elements of a common array without
passing the array as a parameter, then you do (probably) need to use shared
memory. Unfortunately I cannot help you with that since I have never done
it .. take Victor's advice and check out OS-specific NG's.
HTH,
Dave Moore