-
Notifications
You must be signed in to change notification settings - Fork 42
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Specify which C version external functions use #1088
Comments
Comment by Dag Brück on 2 May 2013 15:20 UTC |
Comment by sjoelund.se on 2 May 2013 15:27 UTC The language standard does matter, if only a little. If you force the tool to use a specific language version, if you have different libraries that depend on different language features, you are in trouble. The main benefit is users would actually target a single C version and know their code worked. |
Comment by jmattsson on 2 May 2013 15:49 UTC Also, you shouldn't use |
Comment by sjoelund.se on 2 May 2013 16:41 UTC But for many models, it is a reasonable trade-off considering it is not specified how a tool should compile (and which annotations should be used) for C-sources compiled into libraries. That said, I too dislike that we use Include=#include "myfile.c"; Library="myfile.c" would be nicer. Of course, I also think we should have just allowed inline C in the first place, so I am probably crazy: function f
input Real i;
output Real o;
protected
Real arr[4];
external "C" /* in the header, so global stuff */
#include <math.h>
algorithm
arr := fill(1,4);
external "C" /* in the algorithm section, so access local variables directly in the code for some C subset */
if (i<0.5) {
o = cos(sin(arr[2]));
} else {
o = 0.0;
}
end external;
o := arr[3] + o;
end f; |
Comment by hansolsson on 2 May 2013 17:06 UTC That is normally the same regardless of C-language version - and the code could be written in any language as long the code can be called as though it was C-code. For included code it makes sense to go for the common stable ground, i.e. C89. |
Comment by sjoelund.se on 2 May 2013 17:12 UTC |
Comment by thiele on 6 May 2013 07:15 UTC Having worked at libraries that extensively use external C code it turned out that (despite some disadvantages) the most robust way of interfacing to C was to just use the However, I also don't like to have to "misuse" the What would be more //urgently// needed in my opinion is a mechanism to give a more fine grained control over a build process involving external C code. E.g., s.th. like this: Of course, complete control of a C/C++ build process (especially if several platforms shall be supported) is arbitrarily extensive, therefore one would need to find a design compromise which should cover the most common use-cases. |
Comment by hansolsson on 23 Sep 2013 16:50 UTC |
Comment by hansolsson on 31 Mar 2016 12:28 UTC
Corrected in r9239. |
Comment by m.thorade on 15 Nov 2016 10:05 UTC One example function that was added in C99 is erf,
Is this code illegal? According to MLS_3.3? According to MLS_3.4? Related: thorade/ExtraMath#4 |
Comment by beutlich on 15 Nov 2016 10:10 UTC |
Comment by hansolsson on 15 Nov 2016 11:01 UTC
We could, although I think the names are normally C89, C99 and C11 (without spaces) - even though formally we now only have "ISO/IEC 9899:2011" as C11. The problem is how to use this information:
The implication is thus that we should state that C99/C11 should only be used when necessary; which means that C11 is practically never necessary. |
Comment by beutlich on 15 Nov 2016 11:59 UTC
I prefer that simple solution. It is similar to what I proposed in thorade/ExtraMath#3. |
Comment by beutlich on 4 Jan 2017 14:13 UTC |
Comment by dag on 9 Jan 2017 09:20 UTC
|
Comment by beutlich on 9 Jan 2017 10:01 UTC
Sure. But nevertheless the interface should be clearly defined.
To me, it looks like https://github.com/thorade/ExtraMath (which explicitly uses C99 features) is legal according to MLS 3.3 but no longer accroding to MLS 3.4. I want to avoid this and say that C89 is recommended. So tools should not add -std=C89 as compiler flag. |
Comment by dag on 9 Jan 2017 10:16 UTC
Agreed. Maybe "C89 or later", we need not support any earlier version. |
Comment by volker.beuter on 10 Jan 2017 09:36 UTC
If I understand this discussion correctly the argument is that C99 has additional features we may not want so support from Modelica. So "C89 or later" won't help. If the |
Comment by hansolsson on 28 Feb 2017 17:42 UTC Seems clear - but will need to consider exactly how. |
Comment by dag on 1 Mar 2017 08:26 UTC If we want to go into this level of detail, wouldn't it then make sense to be able to specify which compiler you need? People often write code that only works on a particular compiler, e.g. gcc. |
Comment by beutlich on 1 Mar 2017 13:02 UTC
At least the corresponding library can be set in a compiler-specific way (since #1316 is resolved for Modelica 3.4). Thus the linking should be less error-prone. |
Comment by hansolsson on 14 Mar 2017 15:10 UTC |
Reported by sjoelund.se on 2 May 2013 15:04 UTC
We should specify which C version external functions use in external "C". Which Fortran version is used is clearly defined, but "C" is just... What is it, really?
Maybe we should also add
external "C99"
andexternal "C11"
for those of us who like to program with VLAs (ifexternal "C"
does not imply these features). Or those of us who just like to use//
for line comments...Migrated-From: https://trac.modelica.org/Modelica/ticket/1088
The text was updated successfully, but these errors were encountered: