Reputation: 458
I have two versions of a C++ compiler installed on my computer. One of them recognizes the __COUNTER__
macro and the other does not.
After doing some research to make the program compile in both, I have yet to come across the macro definition for __COUNTER__
. Is this some special macro done by the compiler or can I copy the definition for __COUNTER__
into my source code? If I can copy it, what is the code I need?
Upvotes: 4
Views: 10281
Reputation: 133609
It's a special macro which has been introduced by Visual Studio and I think is now supported by GCC too.
It basically provides a unique counter over integral numbers which can be used to generate unique identifiers.
From GCC release notes:
A new predefined macro
__COUNTER__
has been added. It expands to sequential integral values starting from 0. In conjunction with the##
operator, this provides a convenient means to generate unique identifiers.
If you don't have it available to a compiler you can easily mimic the behavior with a static variable. But I'm not sure what you are compiling so I'm not sure how this counter is used in the code you have available.
Upvotes: 2
Reputation: 129109
__COUNTER__
is a built-in in several common compilers. It is not possible to define manually. If you're stuck with a compiler that doesn't support it, your best option might be to run your code through a preprocessor that does support it before feeding it into the compiler.
Upvotes: 10