I have a source code of a library which has a lot of strange IF, ELSE, FOR, etc. macros for all common C-keywords instead of using just usual if,else,for,while keywords. These macros are defined like this:
#define IF( a) if( increment_if(), a)
where increment_if() function is defined so:
static __inline void increment_if( void) {
// If the "IF" operator comes just after an "ELSE", its counter
// must not be incremented.
... //implementation
}
I don't really understand, what is the purpose of such macros? This library is for a real-time application and I suppose that using such macros must slow-down an application.
Those macros will have two versions, one that is just the plain if statement, and one that counts the number of executions of that statement. The reason for doing this is to make the profiling statistics. If you count the number of executions of each code block, you can account for the amount of time each takes.
In a realtime application, it is far more important that the timing of each operation is predictable so you can calculate if the application is meeting its deadlines. It's not enough to merely be fast, in fact, so long as the deadlines are met, that is all that is required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With