Add unique code to start and end of function in c
<p>I am looking for a way to automatically add code to the start and the beginning of a function. The idea being that i want to profile the running code later. For example i have the functions:</p>

<pre><code>void helloWorld(){
    printf("Hello World!\n");
}

void worldHello(){
    printf("World hello!\n");
}
</code></pre>

<p>I would like to have some kind of macro that expands them to:</p>

<pre><code>void helloWorld(){
    printf("Function id 1 enter");
    printf("Hello World!\n");
    printf("Function id 1 exit");
}

void worldHello(){
    printf("Function id 2 enter");
    printf("World hello!\n");
    printf("Function id 2 exit");
}
</code></pre>

<p>Where the id is uniquely given each time i use my macro. Do anyoen have any good idea on how i could achieve this? i looked at the "__COUNTER__" in GCC but didnt really get it working as i wanted to.</p>