On 19 January 2017 at 02:19, hank fu <hankfumail@xxxxxxxxx> wrote: > 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. No, C and C++ do not support reflection. There are some proposals to add reflection to C++ at some point in the future, but it will be a long time before GCC supports it.