I am in a position where this design will greatly improve the clarity and maintenance requirements of my code.
I am looking for something like this:
#define MY_MACRO(arg) #if (arg)>0 cout<<((arg)*5.0)<<endl; #else cout<<((arg)/5.0)<<endl; #endif
The idea here: A
preprocessor replaces different lines of code depending on the compilation time value of the (constant) macro argument. Of course, I know that this syntax does not work, since it is #considered as a string-ize operator instead of the standard one #if, but I think this demonstrates the function of the preliminary processor I'm trying to achieve.
I know that I could just put the standard ifoperator there, and the compiler / runtime is left to check the values. But this is unnecessary work for the application, when a argconstant value, for example, 10.8or -12.5, which needs to be evaluated only at compile time , will always be transmitted .
The performance requirements for this crunchy application require that all unnecessary execution conditions be eliminated when possible, and many constant values ββand macros must be used (instead of variables and functions) to make this happen. The ability to continue this trend without having to combine pre-processor code with real conditions ifwill make it much cleaner - and, of course, code cleanliness is one of the biggest problems when using macros, especially at this level.
source
share