What is the name of this functionality in C ++?

I wrote C ++ code and mistakenly missed the name of the WSASocket function. However, my compiler did not raise an error and associated my SOCKET with an integer value of 1 instead of a valid socket.

The code in question should look like this:

 this->listener = WSASocket(address->ai_family, address->ai_socktype, address->ai_protocol, NULL, NULL, WSA_FLAG_OVERLAPPED); 

But instead, he looked like this:

 this->listener = (address->ai_family, address->ai_socktype, address->ai_protocol, NULL, NULL, WSA_FLAG_OVERLAPPED); 

Coming from other languages, it looks like it could be some kind of anonymous type. What is the name of this function, in case it is really a function?

What is his purpose?

Itโ€™s hard to find it when you donโ€™t know where to start.

+82
c ++
Nov 18 '14 at 10:12
source share
3 answers

Comma operator and dagger; evaluates the left side, discards its value and, as a result, gives the right side. WSA_FLAG_OVERLAPPED is 1, and this is the result of an expression; all other values โ€‹โ€‹are discarded. A socket is never created.




& cross If not overloaded. Yes, it can be overloaded. No, you should not overload it. Step away from the keyboard, right now!

+151
Nov 18 '14 at 10:15
source share

The compiler evaluates each point in the sequence in parenthesis, and the result is the final WSA_FLAG_OVERLAPPED expression in the expression.

The comma operator is a sequence point in C ++. The expression to the left of the comma is fully evaluated before the expression to the right. The result is always the value on the right. When you get an expression of the form (x1, x2, x3, ..., xn), the result of the expression is always xn .

+21
Nov 18 '14 at 10:15
source share

The comma operator understands your code.

In fact, you set this->listener = WSA_FLAG_OVERLAPPED; which is just syntactically correct.

+21
Nov 18 '14 at 10:15
source share



All Articles