I'm trying to handle winsock's addrinfo pointer with the unique_ptr. After doing some research I found an answer that wasn't really explained very well, so now I'm confused. (The answer I'm talking about: Smart pointers with addrinfo struct)
So my general understanding of unique_ptr says that the syntax is as follows:
unique_ptr<type of handled data, type of function deleting the data>(pointer, deleter function pointer);
.
A basic example of this would be:
void deleteInt(int* ptr){...}
int* ptr = new int;
unique_ptr(int, void(*)(int*)>(ptr, deleteInt);
Note how the function type doesn't specify a name and simply has (*)
.
Now, finally, onto my question:
In the answer I mentioned above, the code does something weird.
Instead of being unique_ptr<addrinfo, void(*)(addrinfo*)>...
it is unique_ptr<addrinfo, void(__stdcall*)(addrinfo*)>...
and nobody seems to question it. How so? How does it change the type of the function? What is __stdcall? Why does it even work since T (name*)()
isn't even valid syntax? Needless to say, simply having void(*)(addrinfo*)
as the function type doesn't work and spits out a bunch of incomprehensible template errors which I don't understand.