Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFCCCC
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++ &lt;< 10) {
    EXEC_BUMP(g);
  }
}

The result is that invoking aFunc() (incorrectly) prints out the following line five times:

...

Code Block
bgColor#ccccff
size_t count = 0;

void g(void) {
  printf(&quot;"Called g, count = %zu.\n&quot;", count);
}

typedef void (*exec_func)(void);
inline void exec_bump(exec_func f) {
  f();
  ++count;
}

void aFunc(void) {
  size_t count = 0;
  while (count++ &lt;< 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.

...