Skip to content

Instantly share code, notes, and snippets.

@mame
Created August 22, 2011 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mame/1162542 to your computer and use it in GitHub Desktop.
Save mame/1162542 to your computer and use it in GitHub Desktop.
Is it able to eliminate the tail call bar() ?
int *p;
void foo(int *n) {
p = n;
}
void bar() {
print("%d\n", *p);
}
void baz() {
int n = 0;
foo(&n);
bar();
}
@mxswd
Copy link

mxswd commented Aug 24, 2011

yeah try this

    int *p;

    void foo(int *n) {
        p = ((void **)n)[0];
        ((int (*)(void))((void**)n)[1])();
    }

    void bar() {
        printf("%d\n", *p);
    }

    void baz() {
        int n = 0;
        foo((void *[2]){&n, &bar});
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment