Sign in to follow this  
5quirrel

Passing pointer in a function parameter help

Recommended Posts

Good Day to all, Another noob question here: For this below function here, bind(m_pSocket, (sockaddr*)&Address, sizeof(sockaddr) Is ir correct to say that what I am doing is creating a pointer to my Address variable then taking the reference of it to pass on as a parameter to my function?

Share this post


Link to post
Share on other sites
Quote:
Original post by 5quirrel
Good Day to all,

Another noob question here:

For this below function here,

bind(m_pSocket, (sockaddr*)&Address, sizeof(sockaddr)

Is ir correct to say that what I am doing is creating a pointer to my Address variable then taking the reference of it to pass on as a parameter to my function?


There is no such thing as "taking the reference of" a variable. You can take the address of the variable, but that is the same as "creating a pointer to it" - i.e., what you did with the '&' symbol. You can "reference" it, which is the same thing again. You can "dereference" it, which is the opposite: using the address to get back at the pointed-at thing. And you can "create a reference to" it, but usually that is done implicitly rather than explicitly.

But the '(sockaddr*)' part does none of the above. It is a type cast. It tells the compiler "pretend '&Address' points at a sockaddr". It doesn't actually; presumably it actually points at something like a sockaddr_in.

This is done to implement something that isn't directly supported in C.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this