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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:32:32+00:00 2026-05-17T01:32:32+00:00

Possible Duplicate: Typedef pointers a good idea? I’ve seen this oddity in many APIs

  • 0

Possible Duplicate:
Typedef pointers a good idea?

I’ve seen this oddity in many APIs I have used:

typedef type_t *TYPE;

My point is that declaring a variable of type TYPE will not make it clear that in fact a pointer is declared.

Do you, like me, think that this brings a lot of confusion? Is this meant to enforce encapsulation, or there are other reasons as well? Do you consider this to be a bad practice?

  • 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-05-17T01:32:33+00:00Added an answer on May 17, 2026 at 1:32 am

    In general, it’s a bad practice. The significant problem is that it does not play well with const:

    typedef type_t *TYPE;
    extern void set_type(TYPE t);
    
    void foo(const TYPE mytype) {
      set_type(mytype);  // Error expected, but in fact compiles
    }
    

    In order for the author of foo() to express what they really mean, the library that provides TYPE must also provide CONST_TYPE:

    typedef const type_t *CONST_TYPE;
    

    so that foo() can have the signature void foo(CONST_TYPE mytype), and at this point we have descended into farce.

    Hence a rule of thumb:

    Make typedefs of structs (particularly incomplete structs), not pointers to those structs.

    If the definition of the underlying struct is not to be publicly available (which is often laudable), then that encapsulation should be supplied by the struct being incomplete, rather than by inconvenient typedefs:

    struct type_t;
    typedef struct type_t type_t;
    
    void set_type(type_t *);
    int get_type_field(const type_t *);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What does SwingUtilities.invokeLater do? SwingUtilities.invokeLater I have seen this little piece of
Possible Duplicate: C++ typedef interpretation of const pointers I just learned that typedef does
Possible Duplicate: Operator overloading in C If I have a struct: typedef struct myStruct
Possible Duplicate: Send NSString via Game Center i have been working on this for
Possible Duplicate: Overloading member methods with typedef aliases as parameters I have following method
Possible Duplicate: Array of zero length I have seen such type of code :-
Possible Duplicate: Forward declarations of unnamed struct If I have typedef struct tagPAGERANGE {
Possible Duplicate: Convert objective-c typedef to its string equivalent I have an enum declared
Possible Duplicate: Find the smallest unused number in SQL Server I have this table
Possible Duplicate: What are the differences between typedef and using in C++11? The following

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.