Is __COUNTER__ macro portable?

前端 未结 3 1228
南方客
南方客 2021-01-13 01:10

I have a piece of code which uses __COUNTER__ macro to generate unique names for variables.

Is this code portable ? I know that GCC and MSVS support it.

相关标签:
3条回答
  • 2021-01-13 01:34

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

    0 讨论(0)
  • 2021-01-13 01:38

    It's definitely not standard.

    It's a compiler extension (GNU C extensions)

    The common predefined macros are GNU C extensions.

    and a Microsoft-specific one,

    Microsoft-Specific Predefined Macros:

    __ COUNTER __

    also supported by clang as language extension.

    The standard doesn't mention it anywhere.

    0 讨论(0)
  • 2021-01-13 01:40

    GCC manual, section Common Predefined Macros, states

    The common predefined macros are GNU C extensions.

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

    As for practical portability: Clang supports it, too.

    0 讨论(0)
提交回复
热议问题