Regarding __COUNTER__ :

I have never heard about it, but as mostly everything else that involves macros it sounds brittle and/or superfluous. Out of my head:
* thread safety?
* what if someone redefines it or, as you mention - use it in headers (especially in non-inline code sections)?

Also, seeing as it is a macro, and thus probably (?) compile-time defined (how can we know?), perhaps the order of compilation could change the output. In other ways - it is probably useless unless applied only inside the source of a single translation unit.

I would have a global function instead:

int counter() {
    static int _cnt = 0;
    return _cnt++;

That way we could also spinlock the insides of that function. But I'm curious to hear if someone knows more.