We are trying to perform performance calculation (CPU cycles taken) on our functions in code.
We want to do this with minimal changes in code.
So if we have somewhere:
print_hi("hello world");
We shall replace it with:
CALL(print_hi("hello world"));
where: CALL expands to:
#define CALL(a) get_ticks( ); a; get_ticks_and_compare()
// Where get_ticks( ), get_ticks_and_compare( ) implement the logic of calculating start and end cycles.
Now, the function being encapsulated may have return values. Say:
result=CALL(add(2,3));
So we change our CALL macro to:
#define CALL(a) (get_ticks( ), a); get_ticks_and_compare();
But we could also have 'a' getting called from a for-loop statement:
for (i = 0; i < add(b, c); i++)
In such a case, we cannot use ';' in the CALL expansion as it would invalidate the for statement.
Please suggest any good ways of writing the CALL( ) macro that can solve our purpose.