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.)

🌐
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.
Discussions

typedef struct or just struct - C++ Forum
In C, names following the struct keyword are in their own lookup table, so they cannot be confused with any other name in code. As a result, if you wish to use a structure type name in C you must specify that it is a struct: The typedef operator makes a type alias — meaning you can create ... More on cplusplus.com
🌐 cplusplus.com
c - Typedef struct vs struct? |Definition difference| - Stack Overflow
The following blocks are outside of main() and before every function (global scope) 1st block: struct flight { int number; int capacity; int passengers; }; With this you can create array, More on stackoverflow.com
🌐 stackoverflow.com
March 17, 2017
Why should we typedef a struct so often in C? - Stack Overflow
I have seen many programs consisting of structures like the one below typedef struct { int i; char k; } elem; elem user; Why is it needed so often? Any specific reason or applicable area? More on stackoverflow.com
🌐 stackoverflow.com
When and why you should or should not use typedef on structs, enums, and unions?
Tbh i always use typedef on structs, enums etc. Whenever i use them, i almost always use my ide to look up the definition anyway, even if i know whether it's a struct or enums. More on reddit.com
🌐 r/embedded
14
6
June 12, 2021
🌐
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.
🌐
mbedded.ninja
blog.mbedded.ninja › programming › languages › c › the-confusing-differences-between-struct-and-typedef-struct
The Confusing Differences Between struct and typedef struct | mbedded.ninja
October 30, 2022 - If you add typedef to the front of the struct definition like this: ... This changes the meaning of the word after the }, it now becomes an alias for the struct type, and not the name of a variable as it did above. What this does is save you having to type struct Person all the time, now you ...
🌐
Cplusplus
cplusplus.com › forum › beginner › 227625
typedef struct or just struct - C++ Forum
In C, names following the struct ... use a structure type name in C you must specify that it is a struct: The typedef operator makes a type alias — meaning you can create new type names out of other types....
🌐
Cprogramming
cboard.cprogramming.com › a-brief-history-of-cprogramming-com › 9524-typedef-struct-vs-struct.html
typedef struct vs. struct - C Board - Cprogramming.com
January 25, 2002 - because some people code in C not C++ and they want to be able to refer to their structs without typing 'struct' each time. ... typedef struct == bad struct == good The only thing typedef does in this situation is hide the fact that the programmer is using a struct.
Find elsewhere
🌐
Quora
quora.com › What-is-the-difference-between-typedef-struct-and-struct-in-C-programming
What is the difference between typedef struct and struct in C programming? - Quora
Answer (1 of 3): The C language standard mandates separate namespaces for different categories of identifiers, including tag identifiers (for [code ]struct[/code]/[code ]union[/code]/[code ]enum[/code]) and ordinary identifiers (for [code ]typedef[/code] and other identifiers). typedef is a keyw...
🌐
Wikipedia
en.wikipedia.org › wiki › Typedef
typedef - Wikipedia
3 weeks ago - Here both C as well as C++ need the struct keyword in the parameter definition. The typedef may be used to define a new pointer type.
🌐
Quora
quora.com › What-is-the-difference-between-typedef-struct-and-struct
What is the difference between typedef struct and struct? - Quora
To avoid polluting global namespace ... in APIs to signal aggregate types. ... typedef struct creates the struct type and a typedef alias so the type can be used without the struct keyword....
🌐
TutorialsPoint
tutorialspoint.com › difference-between-struct-and-typedef-struct-in-cplusplus-program
Difference between \\\'struct\\\' and \\\'typedef struct\\\' in C++ program?
May 26, 2025 - In C++ program, struct is a keyword used to define a structure, while typedef is a keyword that is used to create an alias for a data type. In this article, we will discuss the difference between struct and typedef struct in C++. Struct in C++ Struc
🌐
Delft Stack
delftstack.com › home › howto › struct and typedef struct in c
Difference Between Struct and Typedef Struct in C | Delft Stack
October 12, 2023 - The typedef keyword creates a brand-new name to an already existing data type but does not create the new data type. We can have a cleaner and more readable code if we use the typedef struct, and it also saves us (the programmer) from keystrokes.
🌐
Codemia
codemia.io › knowledge-hub › path › typedef_struct_vs_struct_definitions
typedef struct vs struct definitions
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
🌐
Educative
educative.io › edpresso › how-to-use-the-typedef-struct-in-c
How to use the typedef struct in C
July 1, 2019 - Using typedef struct results in a cleaner, more readable code, and saves the programmer keystrokes​. However, it also leads to a more cluttered global namespace which can be problematic for large programs. Remember, typedef keyword adds a new name for some existing data type but does not create a new type...
🌐
Crustc
crustc.com › home › typedef struct vs struct definitions in c
Typedef Struct vs Struct Definitions in C - crustc
July 24, 2023 - While struct is incredible, it can become cumbersome to constantly write struct before every instance of our defined type, typedef solves this issue. typedef is a keyword in C that allows us to create an alias for existing data types.
Top answer
1 of 16
590

As Greg Hewgill said, the typedef means you no longer have to write struct all over the place. That not only saves keystrokes, it also can make the code cleaner since it provides a smidgen more abstraction.

Stuff like

typedef struct {
  int x, y;
} Point;

Point point_new(int x, int y)
{
  Point a;
  a.x = x;
  a.y = y;
  return a;
}

becomes cleaner when you don't need to see the "struct" keyword all over the place, it looks more as if there really is a type called "Point" in your language. Which, after the typedef, is the case I guess.

Also note that while your example (and mine) omitted naming the struct itself, actually naming it is also useful for when you want to provide an opaque type. Then you'd have code like this in the header, for instance:

typedef struct Point Point;

Point * point_new(int x, int y);

and then provide the struct definition in the implementation file:

struct Point
{
  int x, y;
};

Point * point_new(int x, int y)
{
  Point *p;
  if((p = malloc(sizeof *p)) != NULL)
  {
    p->x = x;
    p->y = y;
  }
  return p;
}

In this latter case, you cannot return the Point by value, since its definition is hidden from users of the header file. This is a technique used widely in GTK+, for instance.

UPDATE Note that there are also highly-regarded C projects where this use of typedef to hide struct is considered a bad idea, the Linux kernel is probably the most well-known such project. See Chapter 5 of The Linux Kernel CodingStyle document for Linus' angry words. :) My point is that the "should" in the question is perhaps not set in stone, after all.

2 of 16
263

It's amazing how many people get this wrong. PLEASE don't typedef structs in C, it needlessly pollutes the global namespace which is typically very polluted already in large C programs.

Also, typedef'd structs without a tag name are a major cause of needless imposition of ordering relationships among header files.

Consider:

#ifndef FOO_H
#define FOO_H 1

#define FOO_DEF (0xDEADBABE)

struct bar; /* forward declaration, defined in bar.h*/

struct foo {
  struct bar *bar;
};

#endif

With such a definition, not using typedefs, it is possible for a compiland unit to include foo.h to get at the FOO_DEF definition. If it doesn't attempt to dereference the 'bar' member of the foo struct then there will be no need to include the "bar.h" file.

Also, since the namespaces are different between the tag names and the member names, it is possible to write very readable code such as:

struct foo *foo;

printf("foo->bar = %p", foo->bar);

Since the namespaces are separate, there is no conflict in naming variables coincident with their struct tag name.

If I have to maintain your code, I will remove your typedef'd structs.

🌐
OpenGenus
iq.opengenus.org › typedef-struct-in-c
typedef struct in C [Explained]
December 5, 2022 - In C language struct is a great way to group several related variables of different data type all at one place. typdef is yet another way used for declaring the type of structure in C language. More so the fact that, typedef gives freedom to the users by allowing them to create their own data types.
🌐
freeCodeCamp
freecodecamp.org › news › structured-data-types-in-c-struct-and-typedef-explained-with-examples
Structured data types in C - Struct and Typedef Explained with Examples
February 1, 2020 - Unions are declared in the same was as structs, but are different because only one item within the union can be used at any time. typedef union{ int circle; int triangle; int ovel; }shape;