Last active
August 29, 2015 13:57
-
-
Save euank/cae2773776741ff46049 to your computer and use it in GitHub Desktop.
Just demonstrating c behavior that allows a non-returning function to still accidentally return the right value.
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 <stdlib.h> | |
#include <stdio.h> | |
int *getOne() { | |
register int eax asm("eax"); | |
printf("eax is %x before malloc\n", eax); | |
int *one = malloc(sizeof(int)); | |
printf("eax is %x after malloc\n", eax); | |
*one = 1; | |
} | |
int main() { | |
register int eax asm("eax"); | |
printf("eax is %x before call\n", eax); | |
int *test = getOne(); | |
printf("eax is %x after call\n", eax); | |
printf("The address of test is %x\n", test); | |
printf("%d\n", *test); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment