How to make sure a function is only called once

前端 未结 5 1754
半阙折子戏
半阙折子戏 2021-01-31 17:56

Suppose I have a function named caller, which will call a function named callee:

void caller()
{
    callee();
}  

Now caller might be called m

5条回答
  •  生来不讨喜
    2021-01-31 18:22

    Inspired by some people, I think just use a macro to wrap comma expression would also make the intention clear:

    #define CALL_ONCE(func) do {static bool dummy = (func, true);} while(0)
    

提交回复
热议问题