title: Dynamically access member variable of a structure
body: <p>I have different structures and I want to write a general framework to get a sorted list of elements from say a hashtable or list of these structures in C. For example, if I have a structure definition as </p>
  
  <pre><code>struct XYZ{ 
   int a;
   char b[20];
   long time;
  }
  </code></pre>
  
  <p>Suppose I have a list of elements of this structure type. I need to have a functionality, by which I can sort this list by any field of the structure and the field would be as given by user. This kind of use case has to be available for other such structures also and hence this sorting framework should be generic. I was thinking of storing different metadata related to this structure in form of a different auto generated structure using some script. This metadata would store information related to each element in the given structure. This information would include type of the structure(viz integer, string or date: types distinct while performing sorting operations) and a way to access this element in the structure. Now my question is what should ideally be the way to access these elements. One straight forward way is to generate some getter functions for each of these and set function pointers of the getter functions in the autogenerated metadata structures. But having a getter function to access each member element would mean a function call for each element access. Would this deter performance of the application ? Can there be any other way to do this? Any other framework ideas to implement the required use case also welcome.</p>