How to print / register variable address in NDK

I am not very strong in C, but now I work with NDK, and I need help in registering the variable address in hexadecimal format. I used __android_log_printto print general log messages, but how to tell C to convert the address of a variable to a char array?

+5
source share
2 answers

I have never worked with Android NDK, but I assume that it __android_log_printworks with printf format characters. In this case you can use %p.

Say we have a variable int a = 10;. To print your address:

printf("%p\n", &a); //This will print in hexadecimal

EDIT

Accepted answer:

__android_log_print(SOME_PRIO, "sometag", "%p", &a);
+7
source

Android NDK, 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;

c

#include <jni.h>
#include <android/log.h>

makefile

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := deneme-jni
LOCAL_SRC_FILES := deneme.c
LOCAL_LDLIBS    := -llog  

include $(BUILD_SHARED_LIBRARY)
+2

All Articles