Static variables local to the function (method) are initialized the first time they use the function in which they are located. (They are initialized to zero when the program loads, and then initialized โcorrectlyโ through code when the function is first introduced.) See the answers to this question . Thus, the movement of this code you propose into a function changes the initialization semantics, and this will not work.
Your source code worked, so you apparently wanted it to move the code inside the function, so it was somehow similar in your mind - or the mind of the code reader - so you can see that your string is a constant name and a name The functions were correct. It is also possible that you can provide registration. And so you want to make DRY.
The traditional (and only) way to achieve this is to use a preprocessor macro that expands into the registration call and function header.
You suggested using the macro yourself - now expand the macro so that it not only generates a registration function, but also a function header.
source share