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

Ali Çehreli acehreli at yahoo.com
Thu Aug 26 05:41:17 UTC 2021


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




More information about the Digitalmars-d mailing list