Skip to content

Instantly share code, notes, and snippets.

@ramajd
Created January 18, 2020 20:45
Show Gist options
  • 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