How to avoid an explicit pointer cast?



 DEVELOP > c-Plus-Plus > How to avoid an explicit pointer cast?

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Dan Oprisan"
Date: 19 Nov 2003 11:19:39 AM
Object: How to avoid an explicit pointer cast?
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 ***** to get along?
.

User: "David Rubin"

Title: Re: How to avoid an explicit pointer cast? 19 Nov 2003 12:43:08 PM
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."
.
User: "Dan Oprisan"

Title: Re: How to avoid an explicit pointer cast? 20 Nov 2003 02:53:33 AM
"David Rubin" <fullname@warpmail.net> schrieb im Newsbeitrag
news:0ROub.124182$Gq.16571767@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).
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER