Created
September 3, 2019 17:36
-
-
Save tov/f620782f6c31378bac3ea18cd83f0f12 to your computer and use it in GitHub Desktop.
Isorecursive function type in C
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> | |
typedef struct rec rec_t; | |
typedef rec_t(*ptr_t)(); | |
struct rec | |
{ | |
ptr_t ptr; | |
}; | |
rec_t odd(); | |
rec_t even() | |
{ | |
puts("even"); | |
return (rec_t) { odd }; | |
} | |
rec_t odd() | |
{ | |
puts("odd"); | |
return (rec_t) { even }; | |
} | |
int main() | |
{ | |
rec_t my_rec = { .ptr = even }; | |
for (int i = 0; i < 16; ++i) | |
my_rec = my_rec.ptr(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment