我想在 c
/c++
中找到一个宏,它获取结构 typedef
和一个指向结构的指针作为输入并打印所有它的内容是这样的:
假设我有一个名为 struct account
的结构。
struct account {
int account_number;
char *first_name;
char *last_name;
float balance;
};
我这样使用它:
struct account my_account= {
.account_number = 321321,
.first_name = 0x12345678,
.last_name = 0,
.balance = 222 };
我想要在 linux 内核/c 语言中有一个看起来像这样的宏:
PRINT_STRUCT_CONTENT(struct_type, pointer)
并打印以下内容:
my_account= {
account_number = 321321,
first_name = 0x12345678,
last_name = 0,
balance = 222
}
想法是在内核中有一种 dir
python 函数
Write a Macro to stringify the contents of a struct
Your most general C macro for printing variable values in different types
最佳答案
您可以使用 print_hex_dump或 print_hex_dump_bytes
示例:
struct mystruct *p;
print_hex_dump_bytes("mystruct: ", DUMP_PREFIX_ADDRESS, p, sizeof(*p));
关于c++ - 如何打印以筛选结构及其所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14572015/