Skip to content

Instantly share code, notes, and snippets.

@topin89
Last active August 22, 2018 11:54
Show Gist options
  • Save topin89/b013b1ea511372ded164a0366550fc07 to your computer and use it in GitHub Desktop.
Save topin89/b013b1ea511372ded164a0366550fc07 to your computer and use it in GitHub Desktop.
C++ static counter (non standart, works for gcc, vc++, clang, icc)
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x64
#include <iostream>
void multiprint(){
static constexpr size_t base = __COUNTER__;
#define i (__COUNTER__ - base - 1)
std::cout << i << std::endl;
std::cout << i << std::endl;
std::cout << i << " " << i <<std::endl;
std::cout << i << " " << i << " " << i << " " << i << " " << i << " " <<std::endl;
#undef i
}
void multiprint2(){
static constexpr size_t base = __COUNTER__;
#define i (__COUNTER__ - base - 1)
std::cout << i << std::endl;
std::cout << i << " " << i << " " << i << " " << i << " " << i << " " <<std::endl;
std::cout << i << std::endl;
std::cout << i << " " << i <<std::endl;
#undef i
}
int main()
{
multiprint();
multiprint2();
std::cout << "Hello, world!\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment