Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structs vs. single parameters in C API #667

Open
t-sommer opened this issue Nov 8, 2019 · 2 comments
Open

Structs vs. single parameters in C API #667

t-sommer opened this issue Nov 8, 2019 · 2 comments
Milestone

Comments

@t-sommer
Copy link
Collaborator

@t-sommer t-sommer commented Nov 8, 2019

Some functions of the C API uses single parameters e.g.

fmi3Status fmi3SetupExperiment(fmi3Instance instance,
                                           fmi3Boolean toleranceDefined,
                                           fmi3Float64 tolerance,
                                           fmi3Float64 startTime,
                                           fmi3Boolean stopTimeDefined,
                                           fmi3Float64 stopTime);

others use structs e.g.

fmi3Status fmi3NewDiscreteStates(fmi3Instance instance,
                                             fmi3EventInfo* eventInfo);

and some use a combination of both e.g.

fmi3Instance fmi3Instantiate(fmi3String        instanceName,
                                 fmi3InterfaceType fmuType,
                                 fmi3String        fmuInstantiationToken,
                                 fmi3String        fmuResourceLocation,
                                 const fmi3CallbackFunctions* functions,
                                 fmi3Boolean       visible,
                                 fmi3Boolean       loggingOn,
                                 const fmi3CoSimulationConfiguration* fmuCoSimulationConfiguration);

Both approaches have their advantages:

Structs

  • can be extended in later versions
  • reduce the number of parameters

single arguments

  • make clear what "goes in" and what "comes out" of the function
  • are consistent (no mix of structs and single parameters)
  • are easier to implement (esp. in languages that have no C interface, e.g. Java or Python)

IMHO we should consider whether we really need structures as parameters and if so, come up with a rule when to use (and how to extend) them.

@t-sommer t-sommer added the discussion label Nov 8, 2019
@t-sommer t-sommer added this to the v3.0 milestone Nov 8, 2019
@chrbertsch

This comment has been minimized.

Copy link
Collaborator

@chrbertsch chrbertsch commented Jan 10, 2020

Regular Design meeting:

Pierre: I do not have a strong opinion. If I would be redoing it, I would try to avoid structs. Structs have the benefit, that one could add elements in the future.
Torsten S: for EventInfo, we have In- and Out-arguments which is not nice

--> Discuss at F2F meeting

@andreas-junghanns

This comment has been minimized.

Copy link
Contributor

@andreas-junghanns andreas-junghanns commented Feb 21, 2020

The initial reason for structs was that we could simply extend without changing the function signature. This turned out to be a hollow reason - we never really used this to prevent API changes.

I would suggest to be consistent and remove all structures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.