473,394 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Two programs accessing the same array

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.

Jul 23 '05 #1
3 1319
<gr********@hotmail.com> wrote...
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?


Shared memory sounds about right. However, neither C nor C++ have that
mechanism. Anything related to IPC is platform- and OS-specific. Please
consider asking in a newsgroup for your OS. A list of suggested NGs is
located in the FAQ. The link to the FAQ can be found in a Welcome message.

V
Jul 23 '05 #2
Victor Bazarov wrote:
Please


That's better.
Jul 23 '05 #3

<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
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: J. Campbell | last post by:
I have a feeling that I'm doing things all ass-backwards (again ;-), and would like some advice. What I want to do is: put some data to memory and then access that memory space as an array of...
27
by: Daniel Lidström | last post by:
Hello! I want to work with individual bytes of integers. I know that ints are 32-bit and will always be. Sometimes I want to work with the entire 32-bits, and other times I want to modify just...
6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
3
by: mtjarrett | last post by:
i having trouble accessing the values from superglobal arrays. there are two situations but i'm pretty sure it's the same problem. here's the deal: on page1.php i have several check boxes. ...
3
by: Olivier BESSON | last post by:
Hello, I have a web service of my own on a server (vb.net). I must declare it with SoapRpcMethod to be used with JAVA. This is a simple exemple method of my vb source : ...
38
by: djhulme | last post by:
Hi, I'm using GCC. Please could you tell me, what is the maximum number of array elements that I can create in C, i.e. char* anArray = (char*) calloc( ??MAX?? , sizeof(char) ) ; I've...
2
by: UJ | last post by:
I have two programs that run at the same time. One creates an XML file of a dataset, the other reads the file. They don't appear to be doing it at the same time. Every once in a while, the XML file...
2
by: ...vagrahb | last post by:
I am having accessing individual rows from a multidimensional array pass to a function as reference CODE: function Declaration int Part_Buffer(char (*buffer),int Low, int High)
16
by: s0suk3 | last post by:
This code #include <stdio.h> int main(void) { int hello = {'h', 'e', 'l', 'l', 'o'}; char *p = (void *) hello; for (size_t i = 0; i < sizeof(hello); ++i) {
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.