I built a simple method as shown below
wchar_t buf[1024] = {}; void logDebugInfo(wchar_t* fmt, ...) { va_list args; va_start(args, fmt); vswprintf( buf, sizeof(buf), fmt, args); va_end(args); } jstring Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env, jobject thiz ) { logDebugInfo(L"test %s, %d..", L"integer", 10); return (*env)->NewStringUTF(env, buf); }
I got the following warning
In the function "Java_com_example_hellojni_HelloJni_stringFromJNI":
warning: passing argument 1 of 'logDebugInfo' from an incompatible pointer type
note: expected 'wchar_t *', but the argument is of type "unsigned int *"
And the resulting string was incorrect. If I removed this L prefix before this format string, that would be weird. But L prefixes were used throughout my legacy code.
At first I know that wchar_t is not portable enough and is very specific to the compiler. The expected wchar_t should be 16 bits in size. I read some other posts that said it was 32 bits for android, but wchar.h provided by the official NDK, he said wchar_t == char, really?
source share