__COUNTER__ (was: Sometimes 100 lines of code can fix your ctfe perf)

Stefan Koch uplink.coder at googlemail.com
Thu Aug 26 09:06:33 UTC 2021


On Thursday, 26 August 2021 at 05:41:17 UTC, Ali Çehreli wrote:
> On 8/24/21 3:33 PM, Ali Çehreli wrote:
>
> > there is no __COLUMN__ or __ID__ or __COUNTER__ or etc. that
> would differ per __LINE__.
>
> I found the following two closed PRs that tried to implement 
> C's __COUNTER__ macro:
>
>   https://github.com/dlang/dmd/pull/10093
>
>   https://github.com/dlang/dmd/pull/10131
>
> As mentioned in the second PR, the semantics can be confusing 
> especially with separate compilation. (I wonder how C works out 
> the semantics.) (And 'static foreach' may be sufficient to 
> handle C's __COUNTER__ for us in a way that leaves the 
> semantics to the user. (I am not sure about that...))
>
> Actually, for this particular use case, I would be happy with a 
> __COLUMN__ counter that would resolve to the location on the 
> line e.g. exactly where the first '_' character of __COLUMN__ 
> appeared. Combined with __FILE_FULL_PATH__ and __LINE__, this 
> would allow us produce unique positions.
>
> Does that make sense?
>
> Ali

The linked `__COUNTER__` (10131)  is actually fine.

I think it does to work inside a static  foreach as well.
whereas `__COLUMN__`   would not give you unique identifiers in a 
static foreach.




More information about the Digitalmars-d mailing list