This expression is a syntax error in C, but assuming you are using C++ it's not grouped how you're expecting:
if (int i = getaddrinfo("localhost", "8000", &crossplat, &actual_addr)!=0){
This will assign the result of getaddrinfo("localhost", "8000", &crossplat, &actual_addr) != 0
to i
, which is always either 0 or 1. Any non-zero return by getaddrinfo()
will leave i
with the value of 1.
You need to declare i
earlier so that you can paranthesize the assignment:
int i;
if ((i = getaddrinfo("localhost", "8000", &crossplat, &actual_addr)) != 0) {
(of course, having done this you'd probably also move the getaddrinfo()
call to the initializer of i
).