www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.ide
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics



c++ - Feature request: __COUNTER__

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
Mar 01 2008