How to avoid an explicit pointer cast?

D

Dan Oprisan

I want to modularize an existing simulation software, i.e. different
processing blocks are be loaded as "plugins" and share the data via
the main program. The main program has no idea about the exchanged
data types, so it will only exchange void pointers between the blocks.

So, each of the modules gets an array of void pointers to the
input/output data from the main program, ptr[3]. In order to access
the data I'm doing something like:

// Internal pointers
double* InSignal;
int* Amplification;
float* OutSignal;
// Assignmet of pointers
InSignal = (double*)ptr[0];
Amplification = (int*)ptr[1];
OutSignal = (float*)ptr[2];
// Simulation
(*OutSignal) = (*InSignal) * (*Amplification);
................ etc

Now, I don't like the fact that I need explicit casts to copy the
external pointer to the internal pointer. I would like to automatize
this assignment, i.e. in a loop. (This would allow to store the
relation between external and internal pointers in a common araray,
used also by other member functions.) Any hint hoe to get along?
 
D

David Rubin

Dan said:
I want to modularize an existing simulation software, i.e. different
processing blocks are be loaded as "plugins" and share the data via
the main program. The main program has no idea about the exchanged
data types, so it will only exchange void pointers between the blocks.

Why can't you define a more type-safe interface for exchanging data
between the driver and the modules? For example, aren't the parameters
always the same types? If not, how does the driver know what parameters
to pass to a module if it doesn't know anything about the module?

/david
 
D

Dan Oprisan

David Rubin said:
blocks.

Why can't you define a more type-safe interface for exchanging data
between the driver and the modules? For example, aren't the parameters
always the same types?

The input/output data is not always of the same type - it will usually
be some larger arrys or data structures. The code with int & double
was just an example.
If not, how does the driver know what parameters
to pass to a module if it doesn't know anything about the module?

Well, first the module has to be interrogated, how many input/output
ports it has, what their function is and of what type they are. Later,
maybe I will represet each module graphically as a box. Then the user
decides how to interconnect the boxes, either graphically or by a
list. The user must take care to match the data correctly. Of course
the the main prog can check if the connections were made correctly
(i.e. have the same declared data type and correct i/o direction).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top