Created
April 12, 2018 15:57
-
-
Save cheery/a6cee9ecbb2cede36b2c5ccb3a414e22 to your computer and use it in GitHub Desktop.
A small demo on using C macros
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
# 1 "symtab_demo.c" | |
# 1 "<built-in>" | |
# 1 "<command-line>" | |
# 1 "/usr/include/stdc-predef.h" 1 3 4 | |
# 1 "<command-line>" 2 | |
# 1 "symtab_demo.c" | |
static symtab symbol_table[] = { | |
{"add", fn_add}, | |
{"print", fn_print}, | |
{"sub", fn_sub}, | |
{NULL, NULL} | |
}; |
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
/* This is a fairly useful feature to know if | |
you are writing anything more complicated in C. | |
Run gcc -E tiny_symtab.c to get the result. | |
*/ | |
#define ENTRY(a) {#a, fn_##a} | |
static symtab symbol_table[] = { | |
ENTRY(add), | |
ENTRY(print), | |
ENTRY(sub), | |
{NULL, NULL} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment