I had to work with legacy code which was overpopulated with macroses by murky C-geniuses over 2 decades ago: it mostly #defines used for emulation of RTTI, generating virtual, non-virtual methods, data members, free functions, code that is describing many kinds of inheritance relations, casts, uncommon looping statestments and so on. #defines are nested. I don't know if it's a matter of taste thing, or habits - but I don't want read, understand, but mostly support and maintain this code. Books about C++ say that macroses should be used rarely and carefully, like goto operator. And I wonder if there is some tool (or compiler option redirecting preprocessor output, or something) that would allow to expand these #define macroses w/o expanding #includes, and maybe w/o touching user supplied filter/list, inside source code. For example (which is just example, I'm ok with common macroses), if I feed this tool with source file containing below code:
#define MAX( a, b ) ( ( a ) > ( b ) ? ( a ) : ( b ) )
int main()
{
int x = -1;
int y = 100;
int max = MAX( x, y );
return 0;
}
It will output source file with:
#define MAX( a, b ) ( ( a ) > ( b ) ? ( a ) : ( b ) )
int main()
{
int x = -1;
int y = 100;
int max = ( ( a ) > ( b ) ? ( a ) : ( b ) );
return 0;
}
Or maybe even prettier than previous excessive-parentheses example:
int max = a > b ? a : b;
Thanks.