Wednesday, November 27, 2013

Be caution fo uninitialized pointer in jni (android ndk)

ClassFoo* foo;if (foo == NULL) {    // do someting..}
I compiled above code in Xcode simulator and iPhone, do something runs correctly as I expect. 

However, on Android (foo == NULL) returns false, so do something never got to execute. I'm compiling the code with APP_CPPFLAGS := -std=c++11 in Application.mk.


So you'd better initialize pointer to NULL to ensure your code runs correctly on both iOS and android... 

ClassFoo* foo = NULL;if (foo == NULL) {    // do someting..}
BTW, working with android NDK and SDK really sucks.

No comments:

Post a Comment