Auto-Incrementing compile-time constant?
Every now & then I have sections of code that look something like this:
static const tag_t TAG_CREATE = 1;
static const tag_t TAG_RELEASE = 2;
static const tag_t TAG_SEAL = 3;
...
Where I declare & define a bunch of magic constants. Being the lazt organizational freak that I am, every now&then I rearrange the order to better group the tag by thier (eventual) functionality. And I hate renumbering them, and inevitably a number is duplicated on accident somewhere.
Anyone ever see an idiom where a value automatically increments everytime it''s reference at compile time? macro-magic, meta-template, or something else?
Magmai Kai Holmlor
"Oh, like you''ve never written buggy code" - Lee
[Look for information | GDNet Start Here | GDNet Search Tool | GDNet FAQ | MSDN RTF[L] | SGI STL Docs | STFW | Asking Smart Questions ]
[Free C++ Libraries | Boost | ACE | Loki | MTL | Blitz++ | wxWindows| Spirit(xBNF)]
Sounds like you are looking for the predefined macro
It's a Visual C++ 7-specific extension, AFAIK. I'd love to see a portable construct, but I'm not sure that's even possible given different translation units etc...
[edited by - spock on August 14, 2002 4:19:49 PM]
__COUNTER__
It's a Visual C++ 7-specific extension, AFAIK. I'd love to see a portable construct, but I'm not sure that's even possible given different translation units etc...
[edited by - spock on August 14, 2002 4:19:49 PM]
Something like this pops to mind:
Then you use _COUNTER_ all over the place. That wouldn''t evaluate at compile-time, but it works And it can increment, demcrement, whatever.
** "Microsoft OLE DB Provider for SQL Server error ''80040e31''" x10 **
int _grefcount=0;#define _COUNTER_ (_grefcount+=1)
Then you use _COUNTER_ all over the place. That wouldn''t evaluate at compile-time, but it works And it can increment, demcrement, whatever.
** "Microsoft OLE DB Provider for SQL Server error ''80040e31''" x10 **
Can''t you generate a file containing the text "const int blah = 1", use some sort of prebuild step to increment it, and simply #include it?
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
isn''t there an #undefine or something? Maybe you could do that, expand counter1 to counter2+1 and then turn counter2 into counter1 and so forth?
Thanks, can''t believe I didn''t think of enum.
Now, if only there was a way to do it across tranlation units.
Magmai Kai Holmlor
"Oh, like you''ve never written buggy code" - Lee
[Look for information | GDNet Start Here | GDNet Search Tool | GDNet FAQ | MSDN RTF[L] | SGI STL Docs | STFW | Asking Smart Questions ]
[Free C++ Libraries | Boost | ACE | Loki | MTL | Blitz++ | wxWindows| Spirit(xBNF)]
Now, if only there was a way to do it across tranlation units.
Magmai Kai Holmlor
"Oh, like you''ve never written buggy code" - Lee
[Look for information | GDNet Start Here | GDNet Search Tool | GDNet FAQ | MSDN RTF[L] | SGI STL Docs | STFW | Asking Smart Questions ]
[Free C++ Libraries | Boost | ACE | Loki | MTL | Blitz++ | wxWindows| Spirit(xBNF)]
Thanks, can''t believe I didn''t think of enum.
Now, if only there was a way to do it across translation units.
Magmai Kai Holmlor
"Oh, like you''ve never written buggy code" - Lee
[Look for information | GDNet Start Here | GDNet Search Tool | GDNet FAQ | MSDN RTF[L] | SGI STL Docs | STFW | Asking Smart Questions ]
[Free C++ Libraries | Boost | ACE | Loki | MTL | Blitz++ | wxWindows| Spirit(xBNF)]
Now, if only there was a way to do it across translation units.
Magmai Kai Holmlor
"Oh, like you''ve never written buggy code" - Lee
[Look for information | GDNet Start Here | GDNet Search Tool | GDNet FAQ | MSDN RTF[L] | SGI STL Docs | STFW | Asking Smart Questions ]
[Free C++ Libraries | Boost | ACE | Loki | MTL | Blitz++ | wxWindows| Spirit(xBNF)]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement