Can we get C/C++ struct's member number, type, name, and format string?

hank fu hankfumail@gmail.com
Thu Jan 19 02:19:00 GMT 2017


Can we get C/C++ struct's member number, type, name, and format string?

Here is one example.
struct c_test_struct_type {
int i_var;
unsigned int ui_var;
long l_var;
unsigned long ul_var;
}
Is there one an operator provided by GCC to determine the member
nubmer of this struct? For example, I hope to get 4 by calling
'__struct_member_number__(struct c_test_struct_type)' .
Is there one an operator provided by GCC to get the member name of
this struct? For example, I hope to get string 'i_var' by calling
'__struct_member_name__(struct c_test_struct_type, 0)'.
Is there one an operator provided by GCC to get the member type of
this struct? For example, I hope to get string 'int' by calling
'__struct_member_type__(struct c_test_struct_type, 0)'.
Is there one an operator provided by GCC to get the formatted string
of this struct? For example, I hope to get string "i_var: %d, ui_var:
%u, l_var: %ld, llvar: %lld" by calling
'__struct_member_print_format__(struct c_test_struct_type, 0)'.

We can simplify the development if we have such operator. I cannot
find them in GCC documents.



More information about the Gcc-help mailing list