Is __COUNTER__ macro portable?

I have a piece of code that uses a macro __COUNTER__

to generate unique names for variables.

Is this code portable? I know GCC and MSVS support it. What about other compilers? Is the macro a specific standard (as far as I know before C ++ 14 it wasn't).

+3


source to share


3 answers


He definitely is n't .

This is a compiler extension ( GNU C extensions )

Common predefined macros are GNU C extensions.

and Microsoft-specific ,



Predefined Macros for Microsoft:

__ COUNTER __

clang is also supported as a language extension.

The standard does not mention it anywhere .

+3


source


GCC Manual, section General Predefined Macros , specify

Common predefined macros are GNU C extensions.



I also haven't seen this macro in the C99, C11, or C ++ 11 standards.

As for practical portability: Clang supports it as well.

+2


source


It seems NO . When I ctrl + f "__COUNTER__" to standard pdf , I didn't find anything> o <

0


source







All Articles