Boost logo

Boost :

Subject: Re: [boost] __COUNTER__ vs __LINE__
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2012-01-11 14:37:43


On 01/11/2012 07:44 PM, Christopher Jefferson wrote:
>
> On 11 Jan 2012, at 18:28, lcaminiti wrote:
>
>> Hello all,
>>
>> Many of Boost macro APIs PP_CAT symbols with either __LINE__ or __COUNTER__
>> to make them unique (MPL_STATIC_ASSERT, SCOPE_EXIT, etc). AFAIK, __LINE__ is
>> C++03 standard while __COUNTER__ is only a MSVC extension. I think using
>> __COUNTER__ instead of __LINE__ might allow to expand a macro multiple times
>> on the same line... but a part from that:
>>
>> What's the reason for using __COUNTER__ on MSVC instead of just using
>> __LINE__ for all compilers?
>
> __LINE__ is restarted for each header file separately, so you can get problems with using a macro on the same line number of different files. I've been bitten by this before. __COUNTER__ is superior.

__COUNTER__ is only per TU, and careless usage can easily lead to ODR
violations.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk