How to avoid an explicit pointer cast?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan Oprisan

    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?

  • David Rubin

    #2
    Re: How to avoid an explicit pointer cast?

    Dan Oprisan wrote:[color=blue]
    > 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.[/color]

    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."

    Comment

    • Dan Oprisan

      #3
      Re: How to avoid an explicit pointer cast?


      "David Rubin" <fullname@warpm ail.net> schrieb im Newsbeitrag
      news:0ROub.1241 82$Gq.16571767@ twister.nyc.rr. com...[color=blue]
      > Dan Oprisan wrote:[color=green]
      > > I want to modularize an existing simulation software, i.e.[/color][/color]
      different[color=blue][color=green]
      > > processing blocks are be loaded as "plugins" and share the data[/color][/color]
      via[color=blue][color=green]
      > > the main program. The main program has no idea about the exchanged
      > > data types, so it will only exchange void pointers between the[/color][/color]
      blocks.[color=blue]
      >
      > Why can't you define a more type-safe interface for exchanging data
      > between the driver and the modules? For example, aren't the[/color]
      parameters[color=blue]
      > always the same types?[/color]

      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.
      [color=blue]
      > If not, how does the driver know what parameters
      > to pass to a module if it doesn't know anything about the module?[/color]

      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).


      Comment

      Working...