language-interoperability

Calling scanf from Ada

独自空忆成欢 提交于 2019-12-02 06:30:57
问题 How do you call scanf from Ada? That is, presumably with an appropriate pragma import declaration, but what would the declaration look like? (I'm interested in how to call C functions of the more unruly variety from Ada, not how to parse strings per se, so I'm not looking for a pure Ada solution. My setup is Gnat, Ubuntu Linux, x64 if it makes a difference.) 回答1: This paper points out that Ada has no way of declaring a function that takes different numbers of parameters of different types.

Incorrect format Exception while trying to call C++ dll from C#

偶尔善良 提交于 2019-12-02 01:39:45
I'm Using C# WPF. I have a C++ test dll as follow: .h: extern "C" __delspec(dllexport) void TestMethod(); .cpp file: extern "C" { __delspec(dllexport) void TestMethod() { MessageBox(0, L"Test", L"Test", MB_ICONINFORMATION); } } C# Code: [DllImport("DllTest.dll", EntryPoint = "TestMethod")] public static extern void TestMethod(); And when i'm trying to call to TestMethod i got exception: an attempt was made to load a program with an incorrect format What i'm doing wrong? Thanks! This seems to be 32bit/ 64 bit problem. Seems like your C++ dll and C# calling assembly are built for different

How should I test Kotlin extension functions?

人走茶凉 提交于 2019-12-01 15:22:13
Can somebody tell me how should I unit-test extension functions in Kotlin? Since they are resolved statically should they be tested as static method calls or as non static ? Also since language is fully interoperable with Java, how Java unit test for Kotlin extension functions should be performed ? Well, to test a method, whether static or not, you call it as real code would do, and you check that it does the right thing. Assuming this extension method, for example, is defined in the file com/foo/Bar.kt: fun String.lengthPlus1(): Int { return this.length + 1 } If you write your test in Kotlin

Embed bash in python

最后都变了- 提交于 2019-11-30 03:19:50
I am writting a Python script and I am running out of time. I need to do some things that I know pretty well in bash, so I just wonder how can I embed some bash lines into a Python script. Thanks ghostdog74 If you want to call system commands, use the subprocess module. The ideal way to do it: def run_script(script, stdin=None): """Returns (stdout, stderr), raises error on non-zero return code""" import subprocess # Note: by using a list here (['bash', ...]) you avoid quoting issues, as the # arguments are passed in exactly this order (spaces, quotes, and newlines won't # cause problems): proc

Can functions from the C standard library be used in C++?

故事扮演 提交于 2019-11-30 02:52:44
Right now I'm getting familiar with C and the C standard library and I wonder if my knowledge in this area will be useful when I turn to working with C++ at a later time. Therefore I'd like to know, whether I can use the functions provided by the C standard library in a C++ setting, and also whether and why it would make sense to actually do so. Basile Starynkevitch Yes, C++ was originally designed so that any C library can be easily used in C++. Of course this is slightly less true (in particular, if a C library happens to use some C++ keyword like try or dynamic_cast , it won't work; also,

Embed bash in python

…衆ロ難τιáo~ 提交于 2019-11-29 00:24:57
问题 I am writting a Python script and I am running out of time. I need to do some things that I know pretty well in bash, so I just wonder how can I embed some bash lines into a Python script. Thanks 回答1: If you want to call system commands, use the subprocess module. 回答2: The ideal way to do it: def run_script(script, stdin=None): """Returns (stdout, stderr), raises error on non-zero return code""" import subprocess # Note: by using a list here (['bash', ...]) you avoid quoting issues, as the #

Can functions from the C standard library be used in C++?

左心房为你撑大大i 提交于 2019-11-28 23:47:52
问题 Right now I'm getting familiar with C and the C standard library and I wonder if my knowledge in this area will be useful when I turn to working with C++ at a later time. Therefore I'd like to know, whether I can use the functions provided by the C standard library in a C++ setting, and also whether and why it would make sense to actually do so. 回答1: Yes, C++ was originally designed so that any C library can be easily used in C++. Of course this is slightly less true (in particular, if a C

How to call java objects and functions from CPython?

∥☆過路亽.° 提交于 2019-11-28 18:56:49
I have a python program, which runs on the CPython implementation, and inside it I must call a function defined in a java program. How can I do this? It would be nice to be able to use some java objects too. Jython is not an option. I must run the python part in CPython. The easiest thing to do is Write a trivial CLI for your java "function". (There's no such thing, so I'll assume you actually mean a method function of a Java class.) public class ExposeAMethod { public static void main( String args[] ) { TheClassToExpose x = new TheClassToExpose(); x.theFunction(); } } Compile and build an

What is marshalling? What is happening when something is “marshalled?”

落花浮王杯 提交于 2019-11-28 15:38:12
I know this question has been asked, at least here . But there wasn't a satisfactory answer, at least not to me. There is a lot of talk about marshalling as regards interoperating with unmanaged code, but what about marshalling from one thread to another, as we have to do in .NET sometimes. This makes me ask, what is marshalling, really? When you give a definition of marshalling, how would you define it so that it is explaining the case of interoperability, as well as the cases where you are "marshalling" between threads? Computations often need to move data from one site to another, and don't

How do multiple languages interact in one project?

[亡魂溺海] 提交于 2019-11-27 16:47:20
I heard some people program in multiple languages in one project. I can't imagine how the languages interact with each other. I mean there is no Java method like myProgram.callCfunction(parameters); never happens or am I wrong? Having multiple languages in one project is actually quite common, however the principles behind are not always simple. In the simple case, different languages are compiled to the same code. For example, C and C++ code typically is compiled into machine assembler or C# and VB.Net is compiled into IL (the language understood by the .NET runtime). It gets more difficult