By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,331 Members | 1,432 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,331 IT Pros & Developers. It's quick & easy.

How to avoid an explicit pointer cast?

P: n/a
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?

Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Dan Oprisan wrote:
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

--
"As a scientist, Throckmorton knew that if he were ever to break wind in
the echo chamber, he would never hear the end of it."

Jul 22 '05 #2

P: n/a

"David Rubin" <fu******@warpmail.net> schrieb im Newsbeitrag
news:0R**********************@twister.nyc.rr.com.. .
Dan Oprisan wrote:
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?
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).
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.