Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

71%
+3 −0
Q&A Question regarding an error message in my compiler to do with my code on linked list.

To use the identifier Node without typing struct Node, you must use a typedef: typedef struct Node{ // this here is a stuct tag int data; struct Node* next; // this has to be struct Node...

posted 2y ago by Lundin‭  ·  edited 2y ago by Lundin‭

Answer
#3: Post edited by user avatar Lundin‭ · 2022-01-13T15:27:48Z (over 2 years ago)
  • To use the identifier `Node` without typing `struct Node`, you must use a `typedef`:
  • typedef struct Node{ // this here is a stuct tag
  • int data;
  • struct Node* next; // this has to be struct Node, refers to the above tag
  • }Node; // but from this line and onward we can use Node
  • `typedef` and struct tags reside in different namespaces, why we can use the same identifier `Node` twice for seemingly unrelated purposes. Since a linked list node needs to be self-referring, we have to use the struct tag so the compiler knows what to do until the struct type definition is completed at the final `;`
  • Another equivalent alternative would be a forward declaration:
  • typedef struct Node Node; // forward declaration inside a typedef
  • struct Node{ // struct tag
  • int data;
  • Node* next; // now the compiler knows what Node is before the struct is complete
  • };
  • Note that C++ is different here.
  • To use the identifier `Node` without typing `struct Node`, you must use a `typedef`:
  • typedef struct Node{ // this here is a stuct tag
  • int data;
  • struct Node* next; // this has to be struct Node, refers to the above tag
  • }Node; // but from this line and onward we can use Node
  • `typedef` and struct tags reside in different namespaces, why we can use the same identifier `Node` twice for seemingly unrelated purposes. Since a linked list node needs to be self-referring, we have to use the struct tag so the compiler knows what to do until the struct type definition is completed at the final `;`
  • Another equivalent alternative would be a forward declaration:
  • typedef struct Node Node; // forward declaration inside a typedef
  • struct Node{ // struct tag to associate this with the above typedef
  • int data;
  • Node* next; // now the compiler knows what Node is before the struct is complete
  • };
  • Note that C++ is different here.
#2: Post edited by user avatar Lundin‭ · 2022-01-13T15:26:47Z (over 2 years ago)
  • To use the identifier `Node` without typing `struct Node`, you must use a `typedef`:
  • typedef struct Node{ // this here is a stuct tag
  • int data;
  • struct Node* next; // this has to be struct Node, refers to the above tag
  • }Node; // but from this line and onward we can use Node
  • Note that C++ is different here.
  • To use the identifier `Node` without typing `struct Node`, you must use a `typedef`:
  • typedef struct Node{ // this here is a stuct tag
  • int data;
  • struct Node* next; // this has to be struct Node, refers to the above tag
  • }Node; // but from this line and onward we can use Node
  • `typedef` and struct tags reside in different namespaces, why we can use the same identifier `Node` twice for seemingly unrelated purposes. Since a linked list node needs to be self-referring, we have to use the struct tag so the compiler knows what to do until the struct type definition is completed at the final `;`
  • Another equivalent alternative would be a forward declaration:
  • typedef struct Node Node; // forward declaration inside a typedef
  • struct Node{ // struct tag
  • int data;
  • Node* next; // now the compiler knows what Node is before the struct is complete
  • };
  • Note that C++ is different here.
#1: Initial revision by user avatar Lundin‭ · 2022-01-13T15:21:32Z (over 2 years ago)
To use the identifier `Node` without typing `struct Node`, you must use a `typedef`:

    typedef struct Node{ // this here is a stuct tag
        int data;
        struct Node* next; // this has to be struct Node, refers to the above tag
    }Node; // but from this line and onward we can use Node

Note that C++ is different here.