Skip to content

Instantly share code, notes, and snippets.

@alphaKAI
Created March 30, 2019 01:33
Show Gist options
  • Save alphaKAI/abcf88aa5622eaf219bb9ba5f9cd19a5 to your computer and use it in GitHub Desktop.
Save alphaKAI/abcf88aa5622eaf219bb9ba5f9cd19a5 to your computer and use it in GitHub Desktop.
FAKE nested function defintion def in C
#include <stdio.h>
#define INNNER_FUNC_PROT(N, RET, func_prot) \
func_prot; \
RET inner_func_ ##N ## _next();
#define INNNER_FUNC_DEF(N, RET, func_name, func_def) \
func_name (); \
return inner_func_ ## N ## _next(); \
} \
func_def \
RET inner_func_ ## N ## _next() { \
INNNER_FUNC_PROT(1, int, void func());
int f() {
INNNER_FUNC_DEF(1, int, func,
void func() {
int x = 2 * 3;
printf("inner func! x : %d\n", x);
});
return 0;
}
int main(int argc, const char *argv[]) {
f();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment