我想知道是否可以在 C99中迭代传递给可变宏的参数或者使用任何 GCC 扩展?
例如,有没有可能编写一个泛型宏,它接受一个结构及其作为参数传递的字段,并打印结构中每个字段的偏移量?
就像这样:
struct a {
int a;
int b;
int c;
};
/* PRN_STRUCT_OFFSETS will print offset of each of the fields
within structure passed as the first argument.
*/
int main(int argc, char *argv[])
{
PRN_STRUCT_OFFSETS(struct a, a, b, c);
return 0;
}