#ifndef __has_builtin // Optional of course.
#define __has_builtin(x) 0 // Compatibility with non-clang compilers.
#endif
#if __has_builtin(__builtin_dump_struct))
__builtin_dump_struct(your_struct_point, &printf);
#endif
!!!不用再挨个变量加print了!!!
使用如上代码就可以利用编译器函数来实现快速打印结构体内容。
学习CLang编译器内置函数: https://clang.llvm.org/docs/LanguageExtensions.html
如果在安卓native c++,printf打印不出东西,那么就要自己定义printf。
int myPrint(const char *pFormat, ...)
{
char logText[MAXLOGLEN];
va_list args;
va_start(args, pFormat);
vsnprintf(logText, MAXLOGLEN, pFormat, args);
va_end(args);
__android_log_write(ANDROID_LOG_ERROR, "chwit", logText);
return 0;
}
或者用一个string去保存打印的字符串,最后再统一输出:
string chwit_str;
int myPrint(const char *pFormat, ...)
{
char logText[MAXLOGLEN];
va_list args;
va_start(args, pFormat);
vsnprintf(logText, MAXLOGLEN, pFormat, args);
va_end(args);
// __android_l
利用CLang编译器内置函数简化结构体打印与Android日志

文章介绍了如何使用CLang的__builtin_dump_struct编译器内置函数来快速打印结构体内容,以及在AndroidnativeC++环境中,当printf无法正常工作时,如何自定义myPrint函数进行日志输出。同时,文章提到了list_for_each_entry宏在遍历链表并访问结构体成员中的应用。
最低0.47元/天 解锁文章
750

被折叠的 条评论
为什么被折叠?



