Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8016589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:34:44+00:00 2026-06-04T20:34:44+00:00

In WinSock2.h, the invalid socket and socket error are defined as these? Is there

  • 0

In WinSock2.h, the invalid socket and socket error are defined as these? Is there any significance to this?

#define INVALID_SOCKET  (SOCKET)(~0)
#define SOCKET_ERROR            (-1)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:34:46+00:00Added an answer on June 4, 2026 at 8:34 pm

    On a two’s complement system (and Windows is always two’s complement), ~0 is equal to -1, so there’s no significance to the compiler.

    There may be a significance to the reader: ~0 emphasizes that it’s a value with all bits set, whereas -1 emphasizes that it’s a value 1 less than 0.

    Aside:

    On a system which is not two’s complement, and assuming that SOCKET is an unsigned type, it is generally wrong to write (SOCKET)(~0). The reason is that on such systems, ~0 does not represent the value -1, it’s one of INT_MIN, negative zero, or a trap representation. Hence it will not necessarily convert to type SOCKET as the value with all bits zero, rather it will convert as INT_MAX+2, 0, or goodness-knows-what (perhaps the value with all bits set).

    So generally you should initialize unsigned types with -1 to get the value with all bits set. You could use UINT_MAX, or ~0UL, or similar, if you know which unsigned type you’re dealing with. But it’s not worth it, because -1 works for all unsigned types.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have this source: #include <winsock2.h> #include <windows.h> #include <iostream> #pragma comment(lib,"ws2_32.lib") using
How to create and bind socket using winsock2, which will be receiving only packets
Excerpt from winsock2.h: #define FD_SET(fd, set) do { u_int __i;\ for (__i = 0;
I'm trying to receive data on a socket, and it keeps giving me this
I made a socket (Winsock2) in Visual Studio Pro C++ to listen on a
I'm building a socket program in Visual Studio 2003 .NET I #include <winsock2.h> header
I have been getting this error for quite some time now and Google has
I have this error while compiling my Visual C++ project in Visual Studio 2008
in the Winsock2 library getaddrinfo() and freeaddrinfo() was only added in Windows XP and
I have a very simple Winsock2 TCP client - full listing below - which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.