I'm not very strong in C, but I'm working with the NDK right now and I need help logging address of a variable in hex. I've been using __android_log_print
to print generic log messages, but how do I tell C to convert address of a variable to a char array?
I never worked with android NDK, but I'm assuming __android_log_print
works with printf format characters. In that case you may use %p
.
Let's say we have a variable int a = 10;
. To print its address:
printf("%p\n", &a); //This will print in hexadecimal
EDIT:
Accepted answer:
__android_log_print(SOME_PRIO, "sometag", "%p", &a);
I work with Android NDK many times and I have tried before use native logcat.
__android_log_print(6, "deneme", "text"); -> this is error message
typedef enum android_LogPriority {
ANDROID_LOG_UNKNOWN = 0,
ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */
ANDROID_LOG_VERBOSE,
ANDROID_LOG_DEBUG,
ANDROID_LOG_INFO,
ANDROID_LOG_WARN,
ANDROID_LOG_ERROR,
ANDROID_LOG_FATAL,
ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */
} android_LogPriority;
and than include header in c source files
#include <jni.h>
#include <android/log.h>
than makefile look like
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := deneme-jni
LOCAL_SRC_FILES := deneme.c
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With