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

user1234 user1234 at 12.de
Thu Aug 26 11:55:07 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?

Yes, dmd uses something similar to generate unittests names.

__COUNTER__ would have been fine to name symbols because the 
mangles start with the module name so separate compilation would 
not have caused multiple definitions errors.


More information about the Digitalmars-d mailing list