Library Typedefs are fundamentally broken

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 17 02:37:43 PDT 2014


On 9/17/2014 12:30 AM, monarch_dodra wrote:
> On Wednesday, 17 September 2014 at 07:21:13 UTC, Andrej Mitrovic via
> Digitalmars-d wrote:
>> On 9/17/14, bearophile via Digitalmars-d <digitalmars-d at puremagic.com> wrote:
>>> Andrei Alexandrescu:
>>>
>>>> Add a sequence number as a uint, defaulted to 0. -- Andrei
>>>
>>> See discussion:
>>> https://d.puremagic.com/issues/show_bug.cgi?id=12100
>>
>> It's a good thing you found GCC and VC implement this. I think it's
>> another sign that we could use this feature.
>
> Technically, they implement it via macro, and the macro re-expands on every use.
> It's mostly useless outside of ".cpp" files: The identifiers are unstable cross
> compilation units. And if it appears in a .h, it'll be re-expanded to a
> different value on every include. If it appears in a macro, it'll be expanded to
> something different on every macro use too.

It's implemented as a special macro named __COUNTER__ which expands to an 
integer literal, incremented each time.

If such a thing were implemented in D, one could not depend on the values being 
globally unique, nor consistent when a module is compiled vs imported, nor 
consistent when multiple modules are compiled together vs compiled 
independently, nor even any predictable relationship between the values within a 
particular module (because semantic analysis is not supposed to be order dependent).


More information about the Digitalmars-d mailing list