Using C ++ to call windows APIs for non-blocking TCP communication, one line of code is written as follows:
If (socket_error = (sock, (sockaddr *) & ADDR, sizeof (ADDR ))) <br/>{< br/> cout <"bind failed" <Endl; <br/> wsacleanup (); <br/> return 0; <br/>}
This code compilation has no errors or warnings, but the results are not what I want. After debugging for half a day, there was no result. Finally, there is no way. I copied the code to codeblocks and compiled it with GCC. The result is the same. When I checked the code again, I found that the code bound to the local IP address and port was very strange. I wrote the BIND (...) (...). = The right side of the operator is a comma expression, which returns sizeof (ADDR), which is just an integer, so there is no syntax error. The correct code should be as follows:
If (socket_error = BIND (sock, (sockaddr *) & ADDR, sizeof (ADDR ))) <br/>{< br/> cout <"bind failed" <Endl; <br/> wsacleanup (); <br/> return 0; <br/>}
I think when I write code, I should not put BIND (...) written (...), it may be that during the encoding process, we accidentally gave "bind" to Ctrl + X. However, such errors are hard to be found.
If I use C # To write similar code, I believe I will not make such a mistake. Because in. in the. NET platform, the enumerated colors displayed in the editor are different from the general methods and attributes. net objects are self-described, and the powerful smart prompting function reduces the probability of making similar errors. Indeed, a good tool can improve coding efficiency and reduce the chance of making mistakes. Think about it. If. Net does not have any supporting tools such as Visual Studio, it is possible that. NET will not become so popular today.