[LLVMbugs] [Bug 9980] New: Multiple __COUNTER__s

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat May 21 00:32:21 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=9980

           Summary: Multiple __COUNTER__s
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: xocotl at gmail.com
                CC: llvmbugs at cs.uiuc.edu


It would be nice if it were possible to have multiple __COUNTER__s, for example
if __COUNTER__uniquename__ would be a new counter starting at 0.

This idea came to me after looking at
http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html and realizing that
in Clang, instead of __LINE__ for their unique ID, __COUNTER__ would work great
and be far more space efficient (well, after bit shifting it right, as it has
to be used twice...).

However, if one were to use counter to generate unique IDs for macros for
branching like talked about on that site, any other use of the counter could
foul up the endeavor (the starting state being zero). For example, since
__COUNTER__ increments every use, their crReturn requiring two increments, to
use the same ID you have to do the macro as (__COUNTER__ >> 1). However, if
someone used __COUNTER__ once outside of macros defined for these poor-man's
coroutines, the second might end up as a separate number (0, 1 becoming 1, 2,
etc.).

Anyway, it's not very important, but if it's easy give it some consideration.
:)

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list