|
-
May 11th, 2010, 07:47 AM
#1
Windows SOCKET type question
Hello,
On http://www.sockets.com/winsock.htm it says:
Because the SOCKET type is unsigned, compiling existing source code from, for example, a UNIX environment may lead to compiler warnings about signed/unsigned data type mismatches.
This means, for example, that checking for errors when the socket() and accept() routines return should not be done by comparing the return value with -1, or seeing if the value is negative (both common, and legal, approaches in BSD). Instead, an application should use the manifest constant INVALID_SOCKET as defined in winsock.h. For example:
TYPICAL BSD STYLE:
s = socket(...);
if (s == -1) /* or s < 0 */
{...}
PREFERRED STYLE:
s = socket(...);
if (s == INVALID_SOCKET)
{...}
But, when I run a program on Windows and I do this line of code:
int test = INVALID_SCOKET;
test has the value or -1. According to http://www.sockets.com/winsock.htm#Accept accept() returns a SOCKET type, so how can SOCKET have a -1 value if it is an unsigned int?
Regards,
Ellay K.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|