c - Does Android not really have wchar_t? -


i built simple method 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 following warning

in function 'java_com_example_hellojni_hellojni_stringfromjni':
warning: passing argument 1 of 'logdebuginfo' incompatible pointer type
note: expected 'wchar_t *' argument of type 'unsigned int *'

and resulting string not correct. if removed l prefix before formatting string, weird, worked. l prefixes used everywhere in legacy code.

first know wchar_t not portable enough , compiler-specific. size of wchar_t expected supposed 16 bits. read other posts said it's 32 bits android wchar.h, provided official ndk, said wchar_t == char, really?

from ndk r5b docs/standalone-toolchain.html:

 5.2/ wchar_t support: - - - - - - - - - - -  documented, android platform did not support wchar_t until android 2.3. means in practical terms that:    - if target platform android-9 or higher, size of wchar_t     4 bytes, , wide-char functions available in c library     (with exception of multi-byte encoding/decoding functions ,      wsprintf/wsscanf).    - if target prior api level, size of wchar_t 1 byte     , none of wide-char functions work anyway.  recommend developer rid of dependencies on wchar_t type , switch better representations. support provided in android there migrate existing code. 

since targeting android 1.6, looks if wchar_t not suitable you.

even in android 2.3 platform ("android-9"), there still notes in number of places, including wchar.h, imply wchar_t 1 byte , none of wide character library functions implemented. suggests implementation may still dodgy, cautious using wchar_t on any android version.

if you're looking alternative, have found utfcpp excellent , lightweight library.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -