Game Development Reference
In-Depth Information
C vs. C++ Native Function Formats
The function in Listing 11-2 is the C native function that utilizes the Java Native Interface. The C++
version is slightly different, but the underlying mechanisms are the same (see Listing 11-3). The main
differences are
The extern "C" specification
1.
The change from (*env)-> to env-> for accessing the JNI functions
2.
The removal of env as the first parameter of the JNI function call
3.
Listing 11-3. The C++ Equivalent Native Function
extern "C" /* specify the C calling convention */
jstring
Java_robs_gldemo_robsgl20tutorial_GLES20TriangleRenderer_RobsstringFromJNI (JNIEnv* env, jobject thiz
)
{
return env->NewStringUTF("Rob's String Text Message!");
}
Native Types
The JNI native data types and their Java equivalents include
jboolean: This native type is equivalent to the boolean Java type and is unsigned
8 bits in size.
jbyte: This native type is equivalent to the byte Java type and is signed 8 bits in size.
jchar: This native type is equivalent to the char Java type and is unsigned 16 bits
in size.
jshort: This native type is equivalent to the short Java type and is signed 16 bits
in size.
jint: This native type is equivalent to the int Java type and is signed 32 bits in size.
jlong: This native type is equivalent to the long Java type and is signed 64 bits
in size.
jfloat: This native type is equivalent to the float Java type and is 32 bits in size.
jdouble: This native type is equivalent to the double Java type and is 64 bits in size.
Reference Types
The JNI includes some reference types that correspond to various Java objects. See Figure 11-4 for
a list of these reference types in a hierarchical view.
 
Search WWH ::




Custom Search