I noticed this a while ago, but thought there must be a reason for it so I never asked, but I have a question about sfTcpListener_accept since I was doing some binding related work when and reminded myself about it.
Anyways, let's take a quick look at this guy.
sfSocketStatus sfTcpListener_accept(sfTcpListener* listener, sfTcpSocket** connected)
{
CSFML_CHECK_RETURN(listener, sfSocketError);
CSFML_CHECK_RETURN(connected, sfSocketError);
*connected = new sfTcpSocket;
return static_cast<sfSocketStatus>(listener->This.accept((*connected)->This));
}
Is there any reason we give this function the address of the pointer instead of just the pointer itself?
And wouldn't this do the exact same thing?
sfSocketStatus sfTcpListener_accept(sfTcpListener* listener, sfTcpSocket* connected)
{
CSFML_CHECK_RETURN(listener, sfSocketError);
CSFML_CHECK_RETURN(connected, sfSocketError);
connected = new sfTcpSocket;
return static_cast<sfSocketStatus>(listener->This.accept(connected->This));
}
I'm just curious about what the difference is.
The function doesn't want to change the sfTcpSocket object, but the sfTcpSocket* pointer. So it must have a sfTcpSocket** argument (a pointer to what it modifies).
Look:
void blop(T x)
{
x = 0;
}
void blop(T* x)
{
*x = 0;
}
The first one has no effect outside the function, the second has. Right?
Now replace T with the type that you want to modify. Let's say we want to modify an int:
void blop(int* x)
{
*x = 0;
}
Easy. Now we want to modify a sfTcpSocket*:
void blop(sfTcpSocket** x)
{
*x = 0;
}
That all makes sense and all, but what I am saying is that this:
void blop(T* x)
{
x = new T;
}
...
T* tDog;
blop(tDog);
Seems to do the exact same thing as:
void blip(T** x)
{
*x = new T;
}
...
T* tDog;
blip(&tDog);
Which is how sfTcpListener_accept seems to be working.