The purpose of IF, ELSE, FOR macros?

I have the source code of a library that has a lot of weird IF, ELSE, FOR, etc. macros for all common C-keywords, and not for using ordinary if, else, for, while keywords. These macros are defined as follows:

#define IF( a) if( increment_if(), a) 

where the increment_if () function is defined as follows:

 static __inline void increment_if( void) { // If the "IF" operator comes just after an "ELSE", its counter // must not be incremented. ... //implementation } 

I really don’t understand what is the purpose of such macros? This library is intended for a real-time application, and I believe that using such macros should slow down the application.

+4
source share
1 answer

These macros will have two versions: one that is just a simple if operation, and one that counts the number of executions of this operator. The reason for this is compiling profiling statistics. If you count the number of executions of each block of code, you can consider the amount of time that each takes.

In a real-time application, it is much more important that the time of each operation is predictable, so you can calculate whether the application meets the deadlines. This is not enough to just be quick, in fact, as long as the deadlines are met, that’s all it takes.

+10
source

Source: https://habr.com/ru/post/1309094/


All Articles