How does this code work?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
sc[] = bla bla bla a bunch of hex;
int main(void)
{
(*(void(*)()) sc)();
}
This (*(void(*)()) sc)();
specifically is what I'm unsure of.
How does this code work?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
sc[] = bla bla bla a bunch of hex;
int main(void)
{
(*(void(*)()) sc)();
}
This (*(void(*)()) sc)();
specifically is what I'm unsure of.
Sc[] is an array of machine instructions, with each byte described in hexadecimal.
The line in main interprets sc as a pointer to a function that takes no arguments and returns a void, and calls the function.
SC is being cast as a function pointer, and then being called. That means that the code in the SC[] is actually machine instructions (encoded in hex).
(*(void(*)()) sc)();
Casts sc
to a *(void(*)()
which is a pointer to a function returning a void and taking no parameters, and calls the function.