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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:14:52+00:00 2026-05-25T16:14:52+00:00

I’m trying to typedef a struct which contains a pointer to another of the

  • 0

I’m trying to typedef a struct which contains a pointer to another of the same type.

Thats what I thought would be the best version:

typedef struct Element
{
    char value;
    struct Element *next;
} Element;

Why is that variant also compiling + executing?:

typedef struct
{
    char value;
    struct Element *next;
} Element;

To describe the first I’d say: “Name struct Element Element now” and the second as: “Take this anonymous struct and call it Element“

But why can I still declare a struct Element (inside the struct) in the second case?

(Working in GCC and MSVC)

  • 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-25T16:14:53+00:00Added an answer on May 25, 2026 at 4:14 pm

    In the first case, your struct has two equivalent names: struct Element (where Element is a struct tag) and Element (where Element is a typedef, an alias for an existing type).

    In the second case, you just didn’t define a tag for the struct. Normally that would be perfectly valid, but here you’re referring to the nonexistent type struct Element in the declaration of the next member.

    In that context, struct Element is an incomplete type. You can’t declare objects of incomplete types, but you can declare pointers to them.

    The declaration

    typedef struct
    {
        char value;
        struct Element *next;
    } Element;
    

    is legal, but it doesn’t make next a pointer to the enclosing type. It makes it a pointer to some incomplete type, and you won’t be able to refer to it until and unless you declare the full type.

    Your second declaration is one of the plethora of things that don’t make sense, but are still legal C.

    You might consider just omitting the typedef and consistently referring to the type as struct Element. As lot of people like the convenience of having a one-word name for a structure type, but my own personal opinion is that there’s not much benefit to that (unless the type is truly opaque, i.e., users of the type don’t even know it’s a struct). It’s a matter of style.

    Note that you need to refer to the type as struct Element, not Element, within the definition itself, since the typedef name Element isn’t visible yet.

    The fact that the struct tag and the typedef have the same name may seem confusing, but it’s perfectly legititimate. Struct tags and typedefs are in separate namespaces (in the C sense, not the C++ sense); a struct tag can only appear immediately after the struct keyword.

    Another alternative is to separate the typedef from the struct definition:

    typedef struct Element Element;
    
    struct Element {
        char value;
        Element *next;
    };
    

    (You can use an incomplete type name in a typedef.)

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I would like to run a str_replace or preg_replace which looks for certain words
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.