PDA

View Full Version : syntax of (struct sockaddr_in *)p->ai_addr



hojoff79
30th March 2011, 01:56
I'm doing some network programming but I am having trouble understanding exactly what the syntax of this line means. It is:

(struct sockaddr_in *)p->ai_addr

I understand the p->ai_addr points to the element of ai_addr in the object pointed to by p, but I don't understand the beginning part (struct sockaddr_in *) and how that is being applied to the p->ai_addr part.

Thanks in advance.

conner686
30th March 2011, 03:08
That's C code. It is a simple cast, telling the compiler that p->ai_addr is a sockadder_in* rather than whatever type the member actually is (likely a void*).