Created
July 18, 2016 11:56
-
-
Save evdenis/312a1b45206af3a6b4fc57aa99f02605 to your computer and use it in GitHub Desktop.
Test of gcc extensions __builtin_return_address && __label__
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> | |
void * | |
test2(void) | |
{ | |
return __builtin_return_address(1); | |
} | |
void * | |
test1(void *( *func )( void )) | |
{ | |
return (func) ? func() : | |
__builtin_return_address(0); | |
} | |
int main(int argc, char **argv) | |
{ | |
__label__ l1, l2; | |
void *test1_ra, *test2_ra; | |
printf("Main addr: %p;\n", &main); | |
printf("label1: %p; label2: %p;\n", &&l1, &&l2); | |
l1: test1_ra = test1(NULL); | |
l2: test2_ra = test1(&test2); | |
printf("test1: %p; test2: %p;\n", test1_ra, test2_ra); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment