Skip to content

Instantly share code, notes, and snippets.

@ramajd
Created January 18, 2020 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramajd/57f48261a668ab9b4599232b9af85a55 to your computer and use it in GitHub Desktop.
Save ramajd/57f48261a668ab9b4599232b9af85a55 to your computer and use it in GitHub Desktop.
macro concatnation example
#include <stdio.h>
struct command {
char *name;
void (*function)(void);
};
#define MKCMD(cmd) { #cmd, cmd ## _command }
void quit_command() {
printf("quit command executed.\n");
}
void help_command() {
printf("help command executed.\n");
}
int main() {
struct command commands[] = {
MKCMD(quit),
MKCMD(help)
};
commands[0].function();
commands[1].function();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment