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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:39:30+00:00 2026-06-03T12:39:30+00:00

I saw some C code like this: // A: typedef uint32_t in_addr_t; struct in_addr

  • 0

I saw some C code like this:

// A:
typedef uint32_t in_addr_t;
struct in_addr { in_addr_t s_addr; };

And I always prefer like this:

// B:
typedef uint32_t in_addr;

So my question is: what’s the difference / benefit of doing it in A from B?

  • 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-03T12:39:34+00:00Added an answer on June 3, 2026 at 12:39 pm

    It’s a layer to introduce type safety, and it can be helpful ‘for future expansion’.

    One problem with the former is that it’s easy to ‘convert’ a value of a type represented by a typedefed builtin to any of several other types or typedefed builtins.

    consider:

    typedef int t_millisecond;
    typedef int t_second;
    typedef int t_degrees;
    

    versus:

    // field notation could vary greatly here:
    struct t_millisecond { int ms; };
    struct t_second { int s; };
    struct t_degrees { int f; };
    

    In some cases, it makes it a little clearer to use a notation, and the compiler will also forbid erroneous conversions. Consider:

    int a = millsecond * second - degree;
    

    this is a suspicious program. using typedefed ints, that’s a valid program. Using structs, it’s ill-formed — compiler errors will require your corrections, and you can make your intent explicit.

    Using typedefs, arbitrary arithmetic and conversions may be applied, and they may be assigned to each other without warning, which can can become a burden to maintain.

    Consider also:

    t_second s = millisecond;
    

    that would also be a fatal conversion.

    It’s just another tool in the toolbox — use at your discretion.

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

Sidebar

Related Questions

In some code I saw recently there was a structure defined like this: typedef
I saw some code like this: try { db.store(mydata); } finally { db.cleanup(); }
I saw some code written by another developer that looks something like this: var
Just now,I saw some code like this: if(condition){ var xx='sss'; } //do something if(condition){
I saw some code in TCL like this: namespace eval ::info { set count
I saw some code, html form code which looks like this: <form name=form1 method=post
I saw some code like this: while(ajaxCallInProgress) { } ajaxCallInProgress = true; What is
Recently I saw some code like this: <tr> <th> Some label: </th> <td> <input
I saw some code on the apple website that goes like this id <NSFetchedResultsSectionInfo>
Short question, I saw in some old code where a ByteArrayInputStream was created like:

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.