Skip to content

Instantly share code, notes, and snippets.

@dmikurube
Created November 12, 2014 08:52
Show Gist options
  • Save dmikurube/76bca19c5735d2291ef6 to your computer and use it in GitHub Desktop.
Save dmikurube/76bca19c5735d2291ef6 to your computer and use it in GitHub Desktop.
#include <cstdio>
#ifdef DECLARE_PRINTER_
#error "The macro DECLARE_PRINTER_ is duplicated."
#else
#define DECLARE_PRINTER_(SECTION, VALUE_NAME) \
void print_##SECTION##_##VALUE_NAME() { \
printf("%s - %s\n", #SECTION, #VALUE_NAME); \
}
#endif // DECLARE_PRINTER_
DECLARE_PRINTER_(foo, bar);
DECLARE_PRINTER_(bar, baz);
#undef DECLARE_PRINTER_
int main() {
print_foo_bar();
print_bar_baz();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment