-1

I have to calculate the number of times a method is called. So I have a macro A initially set to 0. Can I increment it with my particular method like A++ and return it in the main method.Or how would I use the COUNTER macro.

2 Answers2

0

I have a macro A initially set to 0. Can I increment it with my particular method like A++ ?

No ++ needs a lvalue, you cannot do 0++, as A will be replaced as its value after per-processing.

Why not simply make it as global, or use call by reference ?

P0W
  • 46,614
  • 9
  • 72
  • 119
0

A macro is only processed by the preprocessor, which is only run at compilation and has no knowledge of how many times a function is actually called. As Beta said, you can use a variable to store this count, but even that needs to be done carefully if you have multiple threads calling the method.

Jamie
  • 76
  • 3