Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose of IF, ELSE, FOR macros?

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.

like image 392
psihodelia Avatar asked Dec 29 '22 17:12

psihodelia


1 Answers

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.

like image 186
Andrew McGregor Avatar answered Jan 12 '23 10:01

Andrew McGregor