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

Make ModelicaIO.h usable from a C++ environment #2008

Closed
modelica-trac-importer opened this issue Jan 15, 2017 · 12 comments
Closed

Make ModelicaIO.h usable from a C++ environment #2008

modelica-trac-importer opened this issue Jan 15, 2017 · 12 comments
Assignees
Labels
bug Critical/severe issue L: C-Sources Issue addresses Modelica/Resources/C-Sources
Milestone

Comments

@modelica-trac-importer
Copy link

Reported by ottot on 10 Jun 2016 10:03 UTC
The functions in ModelicaIO.h should be marked as extern "C" when compiled with C++ compiler, see attached patch.


Migrated-From: https://trac.modelica.org/Modelica/ticket/2008

@modelica-trac-importer modelica-trac-importer added bug Critical/severe issue L: C-Sources Issue addresses Modelica/Resources/C-Sources labels Jan 15, 2017
@modelica-trac-importer
Copy link
Author

Comment by hansolsson on 13 Jun 2016 11:13 UTC
We should avoid having defines with generic names such as "EXTERN" since that is likely to cause conflicts.

Either have no define (requires a bit more) - or use a common prefix, such as the existing "MODELICA_".

@modelica-trac-importer
Copy link
Author

Comment by beutlich on 13 Jun 2016 13:04 UTC
There already is EXTERN defined in ModelicaMatIO.h.

@modelica-trac-importer
Copy link
Author

Comment by hansolsson on 13 Jun 2016 13:23 UTC
Replying to [comment:2 beutlich]:

There already is EXTERN defined in ModelicaMatIO.h.

Ah, yes, we should thus rename both of them. If necessary with another ticket.
We are lucky that we have NOT stumbled on this yet, but e.g. f2c uses "Extern" and not "EXTERN" (with completely different definition).

@modelica-trac-importer
Copy link
Author

Comment by beutlich on 13 Jun 2016 13:31 UTC
Right. Will rename to MODELICA_EXTERN (with context of this ticket).

@modelica-trac-importer
Copy link
Author

Modified by beutlich on 15 Jun 2016 15:53 UTC

@modelica-trac-importer modelica-trac-importer added this to the MSL_next-MINOR-version milestone Jan 15, 2017
@modelica-trac-importer
Copy link
Author

Comment by beutlich on 23 Jun 2016 20:40 UTC
Hans: Should we instead utilize the MODELICA_EXPORT macro which alreads is used in ModelicaFFT.c, ModelicaInternal.c, ModelicaRandom.c, ModelicaStrings.c and even in ModelicaIO.c.

It is

#if !defined(MODELICA_EXPORT)
#   define MODELICA_EXPORT
#endif

Proposal: Should we

  • rename EXTERN to MODELICA_EXPORT in ModelicaMatIO.h,
  • add MODELICA_EXPORT in ModelicaStandardTables.h,
  • remove MODELICA_EXPORT from ModelicaIO.c and add it to ModelicaIO.h instead?

This way it will be consistent throughout the C Sources.

@modelica-trac-importer
Copy link
Author

Comment by hansolsson on 28 Jun 2016 14:37 UTC
Replying to [comment:6 beutlich]:

@hans: Should we instead utilize the MODELICA_EXPORT macro which alreads is used in ModelicaFFT.c, ModelicaInternal.c, ModelicaRandom.c, ModelicaStrings.c and even in ModelicaIO.c.

It is

#!c
#if !defined(MODELICA_EXPORT)
#   define MODELICA_EXPORT
#endif

Proposal: Should we
* rename EXTERN to MODELICA_EXPORT in ModelicaMatIO.h,
* add MODELICA_EXPORT in ModelicaStandardTables.h,
* remove MODELICA_EXPORT from ModelicaIO.c and add it to ModelicaIO.h instead?

This way it will be consistent throughout the C Sources.

Yes, that seems like a good general solution.

I assume it would be something like:

#if !defined(MODELICA_EXPORT)
#if defined(__cplusplus)
#   define MODELICA_EXPORT extern "C"
#else
#   define MODELICA_EXPORT
#endif

I hope that works in all cases, since we have for Dymola noticed that there are a few additional cases for various variants (declaration vs. definition, function vs. data).

@modelica-trac-importer
Copy link
Author

Comment by beutlich on 29 Jun 2016 13:21 UTC
Replying to [comment:7 hansolsson]:

I assume it would be something like:

#!c
#if !defined(MODELICA_EXPORT)
#if defined(__cplusplus)
#   define MODELICA_EXPORT extern "C"
#else
#   define MODELICA_EXPORT
#endif

This would only go to the three header files ModelicaIO.h, ModelicaMatIO.h and ModelicaStandardTables.h then, as only these files may get included from a C++ module. Right?

@modelica-trac-importer
Copy link
Author

Comment by hansolsson on 29 Jun 2016 14:05 UTC
Replying to [comment:8 beutlich]:

Replying to [comment:7 hansolsson]:

I assume it would be something like:
{{{
#!c
#if !defined(MODELICA_EXPORT)
#if defined(__cplusplus)

define MODELICA_EXPORT extern "C"

#else

define MODELICA_EXPORT

#endif
}}}
This would only go to the three header files ModelicaIO.h, ModelicaMatIO.h and ModelicaStandardTables.h then, as only these files may get included from a C++ module. Right?

Yes.

@modelica-trac-importer
Copy link
Author

Comment by beutlich on 29 Jun 2016 16:50 UTC
ModelicaMatIO.h does not contain functions visible for the Modelica environment. Thus I am going to keep the EXTERN there as it is now.

@modelica-trac-importer
Copy link
Author

Comment by beutlich on 30 Jun 2016 06:26 UTC
Or rename EXTERN to either MATIO_EXTERN or MODELICAMATIO_EXTERN.

beutlich added a commit to beutlich/ModelicaStandardLibrary that referenced this issue Mar 24, 2017
* Add headers for ModelicaExternalC sources
* Use MODELICA_EXPORT consistently (in header declaration only) and set it to `extern "C"` in case of C++
* Rename EXTERN to MATIO_EXTERN in ModelicaMatIO.h
beutlich added a commit to beutlich/ModelicaStandardLibrary that referenced this issue Mar 27, 2017
* Add headers for ModelicaExternalC sources
* Use MODELICA_EXPORT consistently (in header declaration only) and set it to `extern "C"` in case of C++
* Rename EXTERN to MATIO_EXTERN in ModelicaMatIO.h
beutlich added a commit that referenced this issue Apr 5, 2017
* Add headers for ModelicaExternalC sources
* Use MODELICA_EXPORT consistently (in header declaration only) and set it to `extern "C"` in case of C++
* Rename EXTERN to MATIO_EXTERN in ModelicaMatIO.h
@beutlich
Copy link
Member

beutlich commented Apr 5, 2017

@otronarp @d94pn Resolved by d574148 in master.

@beutlich beutlich closed this as completed Apr 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Critical/severe issue L: C-Sources Issue addresses Modelica/Resources/C-Sources
Projects
None yet
Development

No branches or pull requests

2 participants