#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