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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:22:00+00:00 2026-06-13T22:22:00+00:00

typedef seems to be C++ specific (perhaps in some other languages). I find it

  • 0

typedef seems to be C++ specific (perhaps in some other languages). I find it hides the real data type of the value, thus is confusing someone new to the project. Perhaps it is useful to shorten the typing sometimes. When do you recommend the use of typedef?

I also notice I can’t pass a typedef-ed value to a function that accepts the underlying type?

something like:

typedef string VAL;
VAL s = "x";
func(string x); // if I try to pass `s`, I get something like no instance of function template match argument list
  • 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-13T22:22:02+00:00Added an answer on June 13, 2026 at 10:22 pm

    typedef is a C and C++ language label used to create a new type from an existing type. The best place is to use it with the C programming language with structs such as the following example or to use it to create a new, more abstract type from an existing primitive type (short, long, etc.).

    typedef struct {
        int iValue;
        int jValue;
    } MyValues;
    // declare a variable with this struct
    MyValues aMyValuesStruct;
    

    Before typedef was introduced into C, in order to use the above struct as a type you would have had to do something like the following:

    struct _MyValuesStruct {
        int iValue;
        int jValue;
    };
    // declare a variable with this struct
    struct _MyValuesStruct aMyValuesStruct;
    

    In C++ structs and classes are similar constructs which create new types so the typedef is not as useful for those types of variables. However if you are using a built in primitive type to represent some other, more abstract type then the typedef statement helps you to specify the type in a more abstract way.

    This use of typedef makes it a lot easier to specify a label for a type so that when a programmer is reading the source code they can understand what a particular variable represents. For instance if you have a color value variable that fits in an unsigned short if you use a typedef to create a new type for color value and use it consistently then it is much easier to recognize that a variable contains a color value and not some other kind of an unsigned short.

    What typedef also allows is that it makes it much easier to find all of the places in the source where a particular abstract type is being used and it makes it easier to change the underlying type. For instance if your color value type starts off as a byte so you use typedef to create an abstract type like typedef unsigned char ColorValue; and then later you find that you need to change it from an unsigned char to an unsigned short, there would be a single place to make the change and if your use of the type was reasonably strict, that would be the only place you need to make a change.

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

Sidebar

Related Questions

This might be something too obvious. However, I couldn't find the specific answer though
I have some code which seems unambiguous to me, but gcc4.7 is choking on
The following definition of MyStruct (tag MyStruct) and type definition of type MyStruct seems
So I'm using a boost graph of the following type: typedef boost::adjacency_list<boost::listS, boost::vecS, boost:directedS,
Is there a typedef equivalent in C#, or someway to get some sort of
I have a priority_queue of some object: typedef priority_queue<Object> Queue; Queue queue; From time
For some template typename, I want to make a typedef which is the declared
Given a typedef of: type ID int Is it possible to convert a map[ID]int
typedef struct _ut_slot { ucontext_t uc; .... }*ut_slot; static ut_slot* table; //array of the
This typedef: typedef DWORD WINAPI (* CM_Open_DevNode_Key)(DWORD, DWORD, DWORD, DWORD, PHKEY, DWORD); compiles fine

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.