Boost logo

Boost :

Subject: Re: [boost] __COUNTER__ vs __LINE__
From: Alf P. Steinbach (alf.p.steinbach+usenet_at_[hidden])
Date: 2012-01-11 22:36:15


On 11.01.2012 20:06, Andrey Semashev wrote:
> On Wednesday, January 11, 2012 10:28:25 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?
>
> MSVC has problems with expanding __LINE__ when precompiled headers are used.
> Basically, __COUNTER__ is the only practical option with this compiler when
> the macro is to be expanded in a header.

As I recall, the problem is when the option for edit-and-continue is used.

I had that problem with Petru Marginean's original ScopeGuard code.

With the edit-and-continue option, Visual C++ really messed up the
explansion of __LINE__, so that the ScopeGuard temporary names became
invalid.

Cheers,

- Alf


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