Raj
2018-10-26 10:55:32 UTC
I'm using Android Studio(64-Bit version) on Windows 7(64-Bit) & building
native library using Android-NDK (with the help of Cmake). Below is the
smallest breakdown of my problem.
I'm using the value of sizeof(long) as the size for one of my arrays in the
native C code. Android studio is behaving differently at runtime compared
to compiletime. I'm printing the value of sizeof(long) in a log statement &
it prints 4. Now, for one of my requirement, I need to declare an array as
char c[4 - sizeof(long)];
I know this looks weird, but this is a breakdown of my bigger problem.
Actually we are using the sizeof some structures for allocating the size of
some arrays & the structure has some long variables which are causing
issues & wrong sizes.
The above declaration is throwing an error saying 'Array length can't be
negative' & when I change the value to 8, i.e., when I declare the array as
char c[8 - sizeof(long)];
the error is gone, so the sizeof(long) is being populated to 8 by the
Android Studio & is throwing a pre-processor error for values less than 8,
and if I ignore the pre-processor error & go ahead with compilation, then
the compiler throws up the same error. But the value of sizeof(long) in the
debug print statement below is 4.
__android_log_print(ANDROID_LOG_VERBOSE, "log", "Sizeof(long): %d",
sizeof(long)); // This prints Sizeof(long): 4
I have set the macro to build 32Bit native libraries in my CMakeLists.txt
file, by using set(TARGET_PREFER_32_BIT 1).
Can anyone please help me out with this issue, Is there anything additional
required to be done in Android Studio project setup to get the sizeof(long)
to be 4 at pre-processor level? Is there anything else to be done for
building 32-Bit native libraries? Any help will be very appreciated.
native library using Android-NDK (with the help of Cmake). Below is the
smallest breakdown of my problem.
I'm using the value of sizeof(long) as the size for one of my arrays in the
native C code. Android studio is behaving differently at runtime compared
to compiletime. I'm printing the value of sizeof(long) in a log statement &
it prints 4. Now, for one of my requirement, I need to declare an array as
char c[4 - sizeof(long)];
I know this looks weird, but this is a breakdown of my bigger problem.
Actually we are using the sizeof some structures for allocating the size of
some arrays & the structure has some long variables which are causing
issues & wrong sizes.
The above declaration is throwing an error saying 'Array length can't be
negative' & when I change the value to 8, i.e., when I declare the array as
char c[8 - sizeof(long)];
the error is gone, so the sizeof(long) is being populated to 8 by the
Android Studio & is throwing a pre-processor error for values less than 8,
and if I ignore the pre-processor error & go ahead with compilation, then
the compiler throws up the same error. But the value of sizeof(long) in the
debug print statement below is 4.
__android_log_print(ANDROID_LOG_VERBOSE, "log", "Sizeof(long): %d",
sizeof(long)); // This prints Sizeof(long): 4
I have set the macro to build 32Bit native libraries in my CMakeLists.txt
file, by using set(TARGET_PREFER_32_BIT 1).
Can anyone please help me out with this issue, Is there anything additional
required to be done in Android Studio project setup to get the sizeof(long)
to be 4 at pre-processor level? Is there anything else to be done for
building 32-Bit native libraries? Any help will be very appreciated.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/24d5ab34-25f8-44c4-8fa2-f72f0adc726c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/24d5ab34-25f8-44c4-8fa2-f72f0adc726c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.