Jump to content
  • Advertisement
Sign in to follow this  
5quirrel

Passing pointer in a function parameter help

This topic is 3711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
To be more precise you're taking the address of "Address", and casting it to a pointer of type "sockaddr*".

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!