...
Code Block | ||
---|---|---|
| ||
size_t count = 0; #define EXEC_BUMP(func) (func(), ++count) void g(void) { printf(""Called g, count = %zu.\n"", count); } void aFunc(void) { size_t count = 0; while (count++ << 10) { EXEC_BUMP(g); } } |
The result is that invoking aFunc()
(incorrectly) prints out the following line five times:
...
Code Block | ||
---|---|---|
| ||
size_t count = 0; void g(void) { printf(""Called g, count = %zu.\n"", count); } typedef void (*exec_func)(void); inline void exec_bump(exec_func f) { f(); ++count; } void aFunc(void) { size_t count = 0; while (count++ << 10) { exec_bump(g); } } |
The use of the inline function binds the identifier count to the global variable when the function body is compiled. The name cannot be re-bound to a different variable (with the same name) when the function is called.
...