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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:22:58+00:00 2026-06-17T02:22:58+00:00

I am still learning C and had a question related to something I see

  • 0

I am still learning C and had a question related to something I see fairly often. Please correct me if I’m wrong, is statement 1 the equivalent of statement 2?

  1. (struct sockaddr *) &echoServAddr
  2. struct sockaddr echoServAddr

If I understand this correctly, we are casting &echoServAddr to a struct framed the same as sockaddr.


So is the following code passing a struct by address?

/* Bind to the local address */
if (bind(servSock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0) {
    perror("bind() failed");
    exit(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-17T02:22:59+00:00Added an answer on June 17, 2026 at 2:22 am
    // This declares a variable of type "struct sockaddr"
    struct sockaddr echoServAddr;
    
    // This merely takes a pointer to your structure,
    // It (redundantly) casts that pointer to "struct sockaddr *" 
    struct sockaddr *myPtr = (struct sockaddr *) &echoServAddr;
    
    // This calls the function "bind()" and passes it a pointer to your structure
    if (bind(servSock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0) {
        perror("bind() failed");
        exit(1);
    } 
    

    PS:
    Yes, you can cast one a pointer of one struct type to a pointer of a different struct type.

    And unless the underlying struct’s are in fact compatible, doing so could make you very Sad 🙂

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

Sidebar

Related Questions

I'm still learning C# and just had a basic question about inheritance. Lets say
I just had a quick question as I'm still learning grails. I have a
This is a bit of noob question - I'm still fairly new to C#
I had a look at all the related questions but am still unsure. I
When my current project started I was still learning RoR and we had a
Still learning bash but I had some questions in regards to my script. My
I'm sorry if this is a very simplistic question but I'm still learning the
I am a C# developer. Still learning. I had not learn all the features
Still learning magento coding. I wonder is there a way I can print out
Still learning Objective-C / iPhone SDK here. I think I know why this wasn't

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.