I have a complex C structure DATABSECONTEXT. Developers keep adding different fields in this structure. We review and then accept. But sometimes there is a lack of synchronization. There is a complex routine function1(), where we need to access different fields and work over them. So if any newly added field in the structure if not taken care in function1(), it will be left as NULL. Which is an inconsistent state, and will cause crashes later.
I want to achieve the following: Whenever some field is added in this DATABSECONTEXT structure, there should be some mechanism of forced alert/message to the developer, to re-visit the related function function1().
I thought of maintaining a header file, which will have a macro for each field we touch in function1(). Say for field dbCurrency used in function1() I can do
headerfile1.h
#define dbCurrency_funciton1
field definition macro inside the structure can be modified as:
headerfile2.h
#define funname restruc
#define PASTER(x,y) x ## _ ## y
#define NAME(fun) PASTER(fun, funname)
#define MY_ELEMENT(dtype, mname) dtype mname;\
#ifndef (NAME(mname)) \
#error "please visit funciton1() and add macro @NAME(mname) in headerfile.h"
#endif
struct DATABSECONTEXT
{
MY_ELEMENT(char, newlyAddedElement);
};
but such use of preprocessor directives are not allowed in MACROS.
Went through following links (and many more)but could not find anything working for me. Link1, Link2
Any suggestions on how to achieve this in an elegant way?