◎위챗 : speedseoul
http://codemesh.com/products/junction/faqs_usage/faq_jint.html
One of the challenges of platform- and compiler-portable C++ development is unified treatment of the primitive types. Just for some background: types like int and longare notorious for having different sizes on different platforms or even different compilers within one platform.
Many C++ frameworks create their own preprocessor macros or typedefs that replace built-in primitive types like int and long. Typical type names include int32 for a 32 bit integer and int64 for a 64 bit integer. The Java Native Interface (JNI) already did all the work for us and defined platform- and compiler-portable primitive types. Codemesh now only had to face the choice of whether or not to use them. On the plus side, the JNI definitions are well thought out and consistent. On the minus side, some people hate to have their APIs cluttered with typenames that look "foreign."
Because portability is very important for us, we decided to use the JNI names for the primitive types. We have yet to encounter a platform or compiler where the built-in primitive types don't interoperate well with the JNI definitions. The following table provides the complete mapping:
JNI name | Description | Comments |
---|---|---|
jbyte | 8bit signed integer | can be used synonymously with char |
jchar | 16bit signed integer | |
jdouble | 64bit floating point number | can be used synonymously with double on all supported platforms. |
jfloat | 32bit floating point number | can be used synonymously with float on all supported platforms. |
jint | 32bit signed integer | can be used synonymously with int on all supported 32bit platforms. |
jlong | 64bit signed integer | "built-in" corresponding type differs by platform and compiler. |
jshort | 16bit signed integer | |
jsize | 32bit signed integer |