Question about "!".
-
With regards to: ---> bReadible = !(nStatus == 0); What does this mean? I have never seen code written like this before. BOOL CRawPingDlg::IsSocketReadible(SOCKET socket, DWORD dwTimeout, BOOL& bReadible) { timeval timeout; timeout.tv_sec = dwTimeout / 1000; timeout.tv_usec = (dwTimeout % 1000) * 1000; fd_set fds; FD_ZERO(&fds); FD_SET(socket, &fds); int nStatus = select(0, &fds, NULL, NULL, &timeout); if (nStatus == SOCKET_ERROR) return FALSE; else { bReadible = !(nStatus == 0); return TRUE; } } Thank you
-
With regards to: ---> bReadible = !(nStatus == 0); What does this mean? I have never seen code written like this before. BOOL CRawPingDlg::IsSocketReadible(SOCKET socket, DWORD dwTimeout, BOOL& bReadible) { timeval timeout; timeout.tv_sec = dwTimeout / 1000; timeout.tv_usec = (dwTimeout % 1000) * 1000; fd_set fds; FD_ZERO(&fds); FD_SET(socket, &fds); int nStatus = select(0, &fds, NULL, NULL, &timeout); if (nStatus == SOCKET_ERROR) return FALSE; else { bReadible = !(nStatus == 0); return TRUE; } } Thank you
The ! means NOT. If you have a boolean value like true the operator ! will make it to false. if nStatus has the value zero, the term wil be true. !(nStatus == 0) will make it false. It is the same if you write nStatus != 0. sledge
-
With regards to: ---> bReadible = !(nStatus == 0); What does this mean? I have never seen code written like this before. BOOL CRawPingDlg::IsSocketReadible(SOCKET socket, DWORD dwTimeout, BOOL& bReadible) { timeval timeout; timeout.tv_sec = dwTimeout / 1000; timeout.tv_usec = (dwTimeout % 1000) * 1000; fd_set fds; FD_ZERO(&fds); FD_SET(socket, &fds); int nStatus = select(0, &fds, NULL, NULL, &timeout); if (nStatus == SOCKET_ERROR) return FALSE; else { bReadible = !(nStatus == 0); return TRUE; } } Thank you
esepich wrote: bReadible = !(nStatus == 0); What does this mean? I have never seen code written like this before. The ! negates the statement. if (nStatus == 0) is TRUE, then the ! negates it and bReadible will be FALSE. Douglas A. Wright dawrigh3@kent.edu