Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call C methods from C++/Java/C# code?

Tags:

java

c++

c

c#

Many of today's programming languages are based on C; like C++, C#, Java, Objective-C. So could I call a C method from C++ code? Or call C from Java or C#? Or is this goal out of reach and unreasonable? Please include a quick code sample for my and everyone else's understanding.

like image 912
Mohit Deshpande Avatar asked Jun 13 '10 07:06

Mohit Deshpande


People also ask

Can you call C code from Java?

Java native interface (JNI) is a framework provided by java that enables java programs to call native code and vice-versa. Using JNI a java program has the capability to call the native C code.

Is it possible to call C and C++ functions in Java?

C/C++ and Java are popular programming languages. The Java Native Interface (JNI) is a standard to integrate in a portable way C++ and Java code. JNI works both way i.e. C++ implementation can be called from JAVA and vice versa.

What does C do in Java?

C is a compiled language that is it converts the code into machine language so that it could be understood by the machine or system. Java is an Interpreted language that is in Java, the code is first transformed into bytecode and that bytecode is then executed by the JVM (Java Virtual Machine).


1 Answers

C++,C#, Objective-C, and Java can all call C routines. Here are a few links that will give you an overview of the process needed to call C from each language you asked about.

like image 163
Alan Avatar answered Oct 04 '22 02:10

Alan