3 Replies - 225 Views - Last Post: 30 December 2012 - 03:57 PM Rate Topic: -----

#1 B1gB055  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 30-December 12

question:c++ syntax, (struct*) variable_of_type_struct?

Posted 30 December 2012 - 01:59 PM

(note:this is a question about syntax, not winsock. I am just using winsock as an example of where it has occured)
I have been doing some winsock programing recently when I encounted this peice of code:

error=function(local,(sockaddr*) &server,sizeof(server);


What I am confused about is the ...(sockaddr*) &server... part. What is the meaning of this?
Is This A Good Question/Topic? 0
  • +

Replies To: question:c++ syntax, (struct*) variable_of_type_struct?

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2089
  • View blog
  • Posts: 3,181
  • Joined: 21-June 11

Re: question:c++ syntax, (struct*) variable_of_type_struct?

Posted 30 December 2012 - 02:16 PM

&server takes the address of the server variable. The (sockaddr*) parts casts the address to be of type sockaddr*.
Was This Post Helpful? 1
  • +
  • -

#3 B1gB055  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 30-December 12

Re: question:c++ syntax, (struct*) variable_of_type_struct?

Posted 30 December 2012 - 02:38 PM

Why couldn't I just give the function the address of server?
Was This Post Helpful? 0
  • +
  • -

#4 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2089
  • View blog
  • Posts: 3,181
  • Joined: 21-June 11

Re: question:c++ syntax, (struct*) variable_of_type_struct?

Posted 30 December 2012 - 03:57 PM

Presumably because the function wants an argument of type sockaddr*, but the type of server is something other than sockaddr.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1