log_struct
Primary tabs
It's a macro I define in log.h. It uses something I think is specific
to gcc, called "stringification", which is invoked by using a macro
parameter with a '#' in front of it. Here's the macro definition:
// macro to log fields in structs.
#define log_struct(st, field, format, typecast) \
log_msg(" " #field " = " #format "\n", typecast st->field)
For instance, when I use the macro from log_fi() (in log.c) with
log_struct(fi, flags, 0x%08x, );
The macro expands to
log_msg(" " "flags" " = " 0x%08x" "\n", fi->flags);which is equivalent to
log_msg(" flags = 0x%08x\n", fi->flags);because C concatenates strings that are adjacent.
- vedro-compota's blog
- Log in to post comments
- 4740 reads