473,480 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 hoe to get along?

Jul 22 '05 #1
2 3797
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3189
by: Alex Vinokur | last post by:
========================= Windows 2000 Professional Digital Mars C/C++ 8.36 STLport 4.5.3 ========================= I have got a problem with compilation of the following piece of code using...
1
5630
by: Stub | last post by:
Docs says that "The compiler does not use an explicit constructor to implement an implied conversion of types. It's purpose is reserved explicitly for construction." I put up code of three cases...
9
2348
by: Tanmoy Bhattacharya | last post by:
Hi, This is a question about whether I am right that a particular syntactic sugar is missing in C++. Let me explain with an example. Let us say I have a class for complex numbers, and I want...
0
1766
by: Reece Hart | last post by:
Here's the basic issue: PostgreSQL doesn't use indexes unless a query criterion is of exactly the same type as the index type. This occurs even when a cast would enable the use of an index and...
31
3560
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
26
3015
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
4
10920
by: Hakirato | last post by:
Hi I have this compilation problem when trying to convert C code to C++. My function looks like this: void FTPServer_ThreadLoop( void *arg_p ) { FTPSettings_t* FTPSettings_p;
14
4042
by: Noone | last post by:
Hello all, Ok, I want to create a program that will load plugins (dll's) from a plugin folder. I can create the forms and put them into a dll but I cannot actually add them dynamically at run...
20
3309
by: dinklebaga | last post by:
Hi All, I am writing a program at the moment that will allow me to manually read sectors on a floppy disk and have come into a bit of bother. The program is designed to run in a DOS32/16 environment...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7043
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
7081
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
6921
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...
1
4776
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.