Skip to content

Instantly share code, notes, and snippets.

@evdenis
Created July 18, 2016 11:56
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 evdenis/312a1b45206af3a6b4fc57aa99f02605 to your computer and use it in GitHub Desktop.
Save evdenis/312a1b45206af3a6b4fc57aa99f02605 to your computer and use it in GitHub Desktop.
Test of gcc extensions __builtin_return_address && __label__
#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