How can I generate unique values in the C preprocessor?

If you’re using GCC or MSVC, there is __COUNTER__.

Other than that, you could do something vomit-worthy, like:

#ifndef USED_1
#define USED_1
1
#else
#ifndef USED_2
#define USED_2
2
/* many many more */
#endif
#endif

Leave a Comment