Created
January 18, 2020 20:45
-
-
Save ramajd/57f48261a668ab9b4599232b9af85a55 to your computer and use it in GitHub Desktop.
macro concatnation example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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