Skip to content
Snippets Groups Projects
Commit af4ca63c authored by David Hendriks's avatar David Hendriks
Browse files

made script to write function pointer to char and convert it back to a...

made script to write function pointer to char and convert it back to a function pointer in a different function
parent 5f59a8a1
No related branches found
No related tags found
No related merge requests found
# Compile a shared library
#gcc -shared -o libmean.so.1 -fPIC mean.c
gcc -o main -fPIC main.c
File added
#include <stdio.h>
#include <stddef.h>
typedef int (*fn_def)(void);
int test1()
{
// function to call
printf("Test\n");
}
void convert_and_call(void *fnvptr_val)
{
// convert into pointer
fn_def fnptr = (fn_def)fnvptr_val;
fnptr();
}
int main()
{
void* fnvptr = (void*)&test1;
// print adress
printf("%p\n", &test1);
// cast into char array
char* a=(char*)fnvptr;
// print stuff
printf("%s\n", a);
printf("size: %ld\n",sizeof(a));
// cast into new void thing
void * fnvptr2 = (void*)a;
printf("%p\n", fnvptr2);
// // convert into pointer
convert_and_call(fnvptr2);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment