The common idiom is using both:

typedef struct S { 
    int x; 
} S;

They are different definitions. To make the discussion clearer I will split the sentence:

struct S { 
    int x; 
};

typedef struct S S;

In the first line you are defining the identifier S within the struct name space (not in the C++ sense). You can use it and define variables or function arguments of the newly defined type by defining the type of the argument as struct S:

void f( struct S argument ); // struct is required here

The second line adds a type alias S in the global name space and thus allows you to just write:

void f( S argument ); // struct keyword no longer needed

Note that since both identifier name spaces are different, defining S both in the structs and global spaces is not an error, as it is not redefining the same identifier, but rather creating a different identifier in a different place.

To make the difference clearer:

typedef struct S { 
    int x; 
} T;

void S() { } // correct

//void T() {} // error: symbol T already defined as an alias to 'struct S'

You can define a function with the same name of the struct as the identifiers are kept in different spaces, but you cannot define a function with the same name as a typedef as those identifiers collide.

In C++, it is slightly different as the rules to locate a symbol have changed subtly. C++ still keeps the two different identifier spaces, but unlike in C, when you only define the symbol within the class identifier space, you are not required to provide the struct/class keyword:

 // C++
struct S { 
    int x; 
}; // S defined as a class

void f( S a ); // correct: struct is optional

What changes are the search rules, not where the identifiers are defined. The compiler will search the global identifier table and after S has not been found it will search for S within the class identifiers.

The code presented before behaves in the same way:

typedef struct S { 
    int x; 
} T;

void S() {} // correct [*]

//void T() {} // error: symbol T already defined as an alias to 'struct S'

After the definition of the S function in the second line, the struct S cannot be resolved automatically by the compiler, and to create an object or define an argument of that type you must fall back to including the struct keyword:

// previous code here...
int main() {
    S(); 
    struct S s;
}
Answer from David Rodríguez - dribeas on Stack Overflow
Top answer
1 of 12
1361

The common idiom is using both:

typedef struct S { 
    int x; 
} S;

They are different definitions. To make the discussion clearer I will split the sentence:

struct S { 
    int x; 
};

typedef struct S S;

In the first line you are defining the identifier S within the struct name space (not in the C++ sense). You can use it and define variables or function arguments of the newly defined type by defining the type of the argument as struct S:

void f( struct S argument ); // struct is required here

The second line adds a type alias S in the global name space and thus allows you to just write:

void f( S argument ); // struct keyword no longer needed

Note that since both identifier name spaces are different, defining S both in the structs and global spaces is not an error, as it is not redefining the same identifier, but rather creating a different identifier in a different place.

To make the difference clearer:

typedef struct S { 
    int x; 
} T;

void S() { } // correct

//void T() {} // error: symbol T already defined as an alias to 'struct S'

You can define a function with the same name of the struct as the identifiers are kept in different spaces, but you cannot define a function with the same name as a typedef as those identifiers collide.

In C++, it is slightly different as the rules to locate a symbol have changed subtly. C++ still keeps the two different identifier spaces, but unlike in C, when you only define the symbol within the class identifier space, you are not required to provide the struct/class keyword:

 // C++
struct S { 
    int x; 
}; // S defined as a class

void f( S a ); // correct: struct is optional

What changes are the search rules, not where the identifiers are defined. The compiler will search the global identifier table and after S has not been found it will search for S within the class identifiers.

The code presented before behaves in the same way:

typedef struct S { 
    int x; 
} T;

void S() {} // correct [*]

//void T() {} // error: symbol T already defined as an alias to 'struct S'

After the definition of the S function in the second line, the struct S cannot be resolved automatically by the compiler, and to create an object or define an argument of that type you must fall back to including the struct keyword:

// previous code here...
int main() {
    S(); 
    struct S s;
}
2 of 12
228

struct and typedef are two very different things.

The struct keyword is used to define, or to refer to, a structure type. For example, this:

struct foo {
    int n;
};

creates a new type called struct foo. The name foo is a tag; it's meaningful only when it's immediately preceded by the struct keyword, because tags and other identifiers are in distinct name spaces. (This is similar to, but much more restricted than, the C++ concept of namespaces.)

A typedef, in spite of the name, does not define a new type; it merely creates a new name for an existing type. For example, given:

typedef int my_int;

my_int is a new name for int; my_int and int are exactly the same type. Similarly, given the struct definition above, you can write:

typedef struct foo foo;

The type already has a name, struct foo. The typedef declaration gives the same type a new name, foo.

The syntax allows you to combine a struct and typedef into a single declaration:

typedef struct bar {
    int n;
} bar;

This is a common idiom. Now you can refer to this structure type either as struct bar or just as bar.

Note that the typedef name doesn't become visible until the end of the declaration. If the structure contains a pointer to itself, you have use the struct version to refer to it:

typedef struct node {
    int data;
    struct node *next; /* can't use just "node *next" here */
} node;

Some programmers will use distinct identifiers for the struct tag and for the typedef name. In my opinion, there's no good reason for that; using the same name is perfectly legal and makes it clearer that they're the same type. If you must use different identifiers, at least use a consistent convention:

typedef struct node_s {
    /* ... */
} node;

(Personally, I prefer to omit the typedef and refer to the type as struct bar. The typedef saves a little typing, but it hides the fact that it's a structure type. If you want the type to be opaque, this can be a good thing. If client code is going to be referring to the member n by name, then it's not opaque; it's visibly a structure, and in my opinion it makes sense to refer to it as a structure. But plenty of smart programmers disagree with me on this point. Be prepared to read and understand code written either way.)

(C++ has different rules. Given a declaration of struct blah, you can refer to the type as just blah, even without a typedef. Using a typedef might make your C code a little more C++-like -- if you think that's a good thing.)

🌐
W3Schools
w3schools.com › c › c_typedef.php
C typedef
C Examples C Real-Life Examples C Exercises C Quiz C Code Challenges C Practice Problems C Compiler C Syllabus C Study Plan C Interview Q&A ... The typedef keyword lets you create a new name (an alias) for an existing type.
Discussions

What is the point of typedef struct in C++?
Maybe the code was originally written in C. Or it was just a habit that the author of that code had left over from programming in C. Either way there is no point in writing typedef struct in C++. As you say just struct foo already introduces foo as a typename. As for using struct over class for data classes, the benefit would be that you don't have to spell out public: and, assuming you consistently use struct for plain old data and class for everything else, makes it clear to the reader which kind of type is being defined here. More on reddit.com
🌐 r/cpp_questions
8
8
January 24, 2020
How to use the typedef struct in C?
This technique allows you to define a type name for your structures, making it easier to declare variables of that structure type later in your code. The typedef keyword in C is used to create an alias that can represent a type. More on designgurus.io
🌐 designgurus.io
1
10
June 25, 2024
Is it bad to use typedef?
Programming languages allow you to use the principle of abstraction to define solutions to problems. Typedefs in C are nothing more than syntactic sugar which allows you to define a type synonym for a complex object. You use these type synonyms to make your code more readable and more understandable. It's the same reason you define functions. You want to replace a complex sequence of symbols with a simpler, more meaningful symbol. The true test for whether or not your code is easy to read and maintain is if an equally skilled individual can understand the code you've written. The same applies to you, the author, if you cannot understand the code you've written 6 to 12 months after you last touched it, that's proof that your code was not clearly written. More on reddit.com
🌐 r/C_Programming
58
61
June 27, 2020
Difference between typedef struct and struct when manipulating it from within a function?
The "X"'s don't have to be equal. typedef struct blah { int whatever; } blah; You are creating a type called "blah" so you can declare variables of type "blah": e.g.: blah my_variable = { 5 }; You can also say: struct blah my_variable = { 5 }; I am not really a fan of creating typedef's just to avoid having to type in "struct" or "union" which seems to be why they are used much of the time. I generally prefer to just have: struct blah { int whatever; }; and forget the typedef unless there's a good reason for a typedef. The linux kernel coding style document expresses some opinions about when using typedefs is a good idea and when it is not (at least in the opinions of Linus Torvalds, who seems to know what he's doing): https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst#n359 In addition to the cases listed there, I'll use typedefs for function pointer parameters, just because the function pointer syntax is a little unwieldy. More on reddit.com
🌐 r/C_Programming
6
6
November 15, 2021
🌐
Quora
quora.com › What-is-the-difference-between-typedef-struct-and-class-in-C
What is the difference between 'typedef', 'struct', and 'class' in C++? - Quora
Answer: Hello, “Typedef” gives just another name for an existing type, just like “Johnny Halliday” was just an alias for someone named “Jean-Philippe Smets”, where “struct” and “class” allow you to define an “user defined ...
🌐
GeeksforGeeks
geeksforgeeks.org › c language › how-to-use-typedef-for-struct-in-c
How to use typedef for a Struct in C? - GeeksforGeeks
July 23, 2025 - In C, we use typedef to create aliases for already existing types. For structure, we can define a new name that can be used in place of the original struct name.
🌐
Quora
quora.com › What-are-the-differences-between-using-struct-and-typedefs-in-C-C-When-is-it-appropriate-to-use-one-over-the-other
What are the differences between using struct and typedefs in C/C++? When is it appropriate to use one over the other? - Quora
Answer: The two do completely different things, but they can (and often are) used together. In both C and C++, you use a struct to define a structure, a heterogenous collection of related data members. (In C++, a struct can also contain member functions, constructors, access modifiers, etc., but...
Find elsewhere
🌐
IBM
ibm.com › docs › fr › i › 7.4.0
Examples of typedef definitions
We cannot provide a description for this page right now
🌐
Quora
quora.com › What-is-the-reason-why-we-should-typedef-a-struct-so-often-in-C
What is the reason why we should typedef a struct so often in C? - Quora
Because structs do not define data ... be stored in the symbol table using the typedef keyword (which turns a variable definition into a data type definition) along with the fact that the struct label is optional for variables ...
🌐
cppreference.com
en.cppreference.com › cpp › language › typedef
typedef specifier - cppreference.com
For example, in typedef struct { /* ... */ } S;, S is a typedef name for linkage purposes.
🌐
Educative
educative.io › blog › how-to-use-the-typedef-struct-in-c
How to use the typedef struct in C
May 19, 2025 - In the code below, the structure ... variables of this structure type using just Point. ... The typedef is applied directly to the structure definition itself....
🌐
Facebook
facebook.com › groups › cs50 › posts › 775584965921884
Any explanation of typedef and struct in C programming?
I am sorry i forgot this part.. when declaring our own data type... we use (typedef struct) . what does each one do ? I am guessing typedef is declaring that we are going to define a new type and...
🌐
Hacker News
news.ycombinator.com › item
> Wrap your structs in a typedef NOOoooooo, please stop doing this. unless you a... | Hacker News
January 8, 2023 - NOOoooooo, please stop doing this. unless you are a library author who gets to define things like uint8_t, please do not do this · even BIGGER no. This is completely misunderstanding what a typedef is and what it should be used for
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › difference-between-struct-and-typedef-struct-in-cpp
Struct vs Typedef Struct in C++ - GeeksforGeeks
October 6, 2025 - In C++, the struct keyword is used to define a struct, whereas the typedef keyword is used for creating an alias(new name) for existing datatypes or a user-defined datatypes like class, struct, and union to give them more meaningful names.
🌐
Quora
quora.com › Why-do-we-use-typedef-struct-in-C++
Why do we use typedef struct in C++? - Quora
It is mostly for making the source code easier to read, but also can be used to make a data structure opaque, such as the case with a file pointer form the buffered I/O in “stdio.h” (FILE *). ... It is possible to enforce some requirements for data as well. Suppose a certain type in a library can only be used as a pointer because ... The typedef keyword let’s you define a name for a type.
🌐
Wikipedia
en.wikipedia.org › wiki › Struct_(C_programming_language)
struct (C programming language) - Wikipedia
February 8, 2026 - struct B; struct A { struct B* b; }; struct B { struct A* a; }; Via the keyword typedef, a struct type can be referenced without using the struct keyword.
🌐
w3resource
w3resource.com › c-programming-exercises › c-snippets › difference-between-typedef-struct-and-struct-definitions-with-example.php
C - Difference between typedef struct and struct
November 1, 2025 - In C language, struct is used to define a user-defined data type that groups together variables of different data types under a single name. A typedef can be used to create an alias for an existing data type, including a struct.