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 8198661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:59:47+00:00 2026-06-07T05:59:47+00:00

Reading the code of the C library’s sockets interface, I found this: /* Types

  • 0

Reading the code of the C library’s sockets interface, I found this:

/* Types of sockets.  */
enum __socket_type
{
   SOCK_STREAM = 1,     /* Sequenced, reliable, connection-based
               byte streams.  */
#define SOCK_STREAM SOCK_STREAM
   SOCK_DGRAM = 2,      /* Connectionless, unreliable datagrams
               of fixed maximum length.  */
#define SOCK_DGRAM SOCK_DGRAM
...

This “idiom” is used all over bits/socket.h. I am just curious, what is the purpose of those macros?

  • 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-07T05:59:48+00:00Added an answer on June 7, 2026 at 5:59 am

    These constants used to just be #defines, so what you’re seeing is probably there to protect you from accidentally mixing old and new header files. An advantage of using enum to define the constants is that enum members tend to be available in the debugger, and #define macros don’t.

    If you were to (accidentally) include some other header file that also tries to #define SOCK_STREAM, you would get a compiler warning instead of silently using a possibly incorrect value.

    UPDATE

    Looking through a glibc git repo, I found the specific commit that added the #defines, with this comment:

    * sysdeps/generic/socketbits.h: Also make SOCK_* constants available
    as macros so that #ifdef works.
    * sysdeps/unix/sysv/linux/socketbits.h: Likewise.
    

    There you have it.

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

Sidebar

Related Questions

I was reading though a library of python code, and I'm stumped by this
Reading existing code at work, I wondered how come this could work. I have
I'm reading this code sample : And since I don't know C#, I decided
When I reading the code of CodeIgniter,I found some functions written as follows: function
I find this question during code reading. After search MSDN, it has same issue
I have this code. It's from the Zend Reading Mail example. $message = $mail->getMessage(1);
I was reading XNA library code and inside the type VertexPositionColor , they supress
I was reading a piece of code from the XStreamingReader library (which seems like
This is the full code library ieee; use ieee.std_logic_1164.all; entity move_key_detector is PORT( clk
I've got a small bit of code from a library that does this: #define

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.