huutisnauriainen
huutisnauriainen

Reputation: 1

What does this snippet in C++ do?

What does this snippet of C++ code do? I've tried to read many sources about pointers but I just can't get my head around it.

long address = *((long *)(another_address + 0x0));
int(*function)() = (int(*)())address;

Edit: another_address is a vtable address. I'm trying to port this to Python, and was actually asking about how the pointer stuff works (in the snippet).

Upvotes: 0

Views: 77

Answers (1)

Brady Dean
Brady Dean

Reputation: 3573

(another_address + 0x0) evaluates to another_address, then is cast to long*, then dereferenced.

(int(*)()) address casts address to a function that takes no arguments and returns an int, it is then assigned to function with the same signature.

Upvotes: 1

Related Questions