March 02, 2008
This is originally a Microsoft-specific (VC++ 7.0+) pre-processor feature, but is slowly gaining interest in other areas. I believe GCC 4.3 contains this.

Basically, it resolves, on a per-translation unit basis, to an integral number that increments (starting at 0) each time it is used.

Consider the following program:

    #include <stdio.h>

    #define USE_COUNTER()   printf("%d\n", __COUNTER__)

    int main()
    {
        int i = __COUNTER__;
        int j = __COUNTER__;

        USE_COUNTER();
        USE_COUNTER();
        printf("%d\n", __COUNTER__);
        printf("%d\n", __COUNTER__);
        printf("i = %d\n", i);
        printf("j = %d\n", j);

        return 0;
    }

It produces the following output:

    2
    3
    4
    5
    i = 0
    j = 1

I have an exceedingly useful, er, use for this feature, and would like to be able to offer a wider range of compilers for the library that will be created than just VC++ 7+ and GCC 4.3+.

I recognise that the pre-compiled header stuff might be tricky, but still wanted to request that you consider adding this to DMC++'s armoury. :-)

Cheers

Matt