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

  • Home
  • SEARCH
  • 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 6168443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:41:21+00:00 2026-05-23T22:41:21+00:00

typedef struct tnode { … } Treenode; Since typedef can’t create a new type

  • 0
typedef struct tnode { ... } Treenode;

Since typedef can’t create a new type for us, is this part of the declaration of “struct tnode”? So in the above, is it creating a typedef “Treenode” AND declaring “struct tnode”?

return (Treeptr) malloc(sizeof(Treenode));

Here, since Treenode is a synonym for the entire “struct tnode” declaration, is it necessary to pass the whole declaration to sizeof or can one just do: sizeof(struct tnode) after declaring tnode elsewhere via struct tnode { … };

typedef struct tnode *Treeptr;

Typedef is: typedef old-existing-type newtype; So here.. struct tnode * is the old type which must already exist (must be declared elsewhere) and Treeptr is the synonym for that.. but why can’t we space the thing?? Like so: typedef struct tnode * Treeptr;

typedef int (*PFI)(char *, char *);

What is going on here? the old-type is int and (*PFI)(char , char) is a synonym for int?? If int (*PFI)(char *, char *) is the old-type, what’s the new-type?? What does he mean by saying “In effect typedef is like #define, except that since it’s interpreted by the compiler, it can cope with textual substitutions that are beyond the capabilities of the preprocessor”? In the mentioned example.. why can’t the preprocessor do whatever is being done??

  • 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-23T22:41:23+00:00Added an answer on May 23, 2026 at 10:41 pm

    So in the above, is it creating a typedef “Treenode” AND declaring
    “struct tnode”?

    Yes, there are both declaration and typedef in the same sentence.

    but why can’t we space the thing?? Like so: typedef struct tnode *
    Treeptr

    If you are talking about the * – you can. it is a separate token anyway.

    typedef int (*PFI)(char *, char *);
    

    This is a function type definition;

    typedef int (*PFI)(char *, char *);
    ^ define a type called
                  ^PFI as:
                 ^ pointer
                      ^to function
                       ^that receives two char pointers as arguments
            ^ and returns an int
    

    Now you can use PFI instead of int (*)(char *, char *) (when used as a parameter / variable)

    EDIT:

    Code sample for using function pointer:

    #include <stdio.h>
    
    int add(int a, int b) { return a + b; }
    
    typedef int (*pfi)(int,int);
    
    int main()
    {
        pfi my_func = add;
        int res;
        res = (*my_func)(1,2);
        printf( "add(1,2)=%d", res);
        return res;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

typedef struct Value{ int id; char type; char a; } Value; void fooV(Value v){
I have a struct like this: typedef struct string { unsigned long length; unsigned
typedef struct { nat id; char *data; } element_struct; typedef element_struct * element; void
I have the following struct in C++: #define MAXCHARS 15 typedef struct { char
I have the following construction: typedef struct bucket { char *key; ENTRY *data; struct
I've got a structure as follows: typedef struct { std::wstring DevAgentVersion; std::wstring SerialNumber; }
Given a struct, e.g. typedef struct { int value; } TestStruct; Why does the
I have seen many programs consisting of structures like the one below typedef struct
In rpc.h, the GUID structure is declared as follows: typedef struct _GUID { DWORD
I have the below code in stdafx.h. using namespace std; typedef struct { DWORD

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.