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.

Answer from unwind on Stack Overflow
🌐
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.
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.

Discussions

Whats the difference between a normal struct and a typedef struct?
A struct that isn't typedef'd requires you to use the keyword struct every time you use it as a type (so it'd be struct MyStruct mystruct;). This doesn't apply for structs you typedef. More on reddit.com
🌐 r/C_Programming
17
54
February 20, 2022
programming languages - Why use typedefs for structs? - Software Engineering Stack Exchange
Most arguments center on the idea that typedefs simply hide the actual data type of a variable. For example, Greg Kroah-Hartman, a Linux kernel hacker and documenter, discourages their use for anything except function prototype declarations. He argues that this practice not only unnecessarily obfuscates code, it can also cause programmers to accidentally misuse large structures ... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
April 23, 2013
typedefing a struct
Is there any functional difference (or any other reason to prefer one over the other) between these two methods: typedef struct mystruct { int a... More on thecodingforums.com
🌐 thecodingforums.com
15
September 14, 2007
c programing: using "struct" and "typedef struct" - For Beginners | GameDev.net Forums - GameDev.net
I think the OP gets that part of it. The _t and _s appendages are not part of the language itself. Those are just elements of coding style used to indicate whether the structure has been typedefed or not. I generally typedef all structures as it just makes things easier. More on gamedev.net
🌐 gamedev.net
October 3, 2002
🌐
CodersLegacy
coderslegacy.com › home › learn c++ › how (and why) to use typedef struct in c
How (and why) to use typedef struct in C - CodersLegacy
February 16, 2022 - Some people may not want to have to write the “struct” part every time you create a new struct variable. So in order to resolve this problem, we use typedef.
🌐
W3Schools
w3schools.com › c › c_files_read.php
C Read Files
C Structures C Structs Challenge C Nested Structures C Structs & Pointers C Unions C typedef C Struct Padding
🌐
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...
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
🌐
CSE CGI Server
cgi.cse.unsw.edu.au › ~cs1521 › 26T1 › assignments › ass2 › index.html
COMP1521 26T1 — Assignment 2: Standard Input/Output Library
February 28, 2026 - You should implement struct file, which is currently defined as an empty struct in cs1521_stdio.c. You should only need to include a field for the file descriptor. However, later in the assignment, you will likely need to add additional fields. In cs1521_stdio.h, we have included a typedef for the type struct file:
🌐
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.
🌐
PlantUML
plantuml.com › home › language specification › class diagram
Class Diagram syntax and features
PlantUML class diagram syntax: You can define interfaces, members, relationships, packages, generics, notes... Changing fonts and colors is also possible.
🌐
Wikipedia
en.wikipedia.org › wiki › Struct_(C_programming_language)
struct (C programming language) - Wikipedia
February 8, 2026 - However, some programming style guides advise against this, claiming that it can obfuscate the type. ... typedef struct MyStruct { Type1 member1; Type2 member2; } Thing; // struct MyStruct can now be referred to as 'Thing' Thing thing;
🌐
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 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.
🌐
Binaryupdates
binaryupdates.com › home › structures, typedef and union in c programming
Structures, Typedef and Union in C Programming Language
August 4, 2021 - Let’s assign name to variable ... applies to all other member variables. ... The keyword Typedef is used to give a new symbolic name for the existing name....
🌐
The Coding Forums
thecodingforums.com › archive › archive › c programming
typedefing a struct | C Programming | Coding Forums
September 14, 2007 - Note that in both cases, any reference to the type within its own definition (say, if a mystruct contains a pointer to a mystruct) has to use the name 'struct mystruct', since the typedef name doesn't exist yet. You could even drop the tag, and just declare typedef struct { int a; int b; } mystruct; since you never use the struct tag name anyway.
🌐
Unstop
unstop.com › home › blog › typedef in c | usage with mulitple data types (+examples)
Typedef In C | Usage With Mulitple Data Types (+Examples)
May 15, 2024 - However, note that it cannot be any other reserved keyword. Apply typedef Syntax: Write the typedef keyword followed by the existing data type and the new name (alias), separated by a space.
🌐
NxtWave
ccbp.in › blog › articles › typedef-in-c
Typedef In C: What is, How to Use & More
In C programming, the typedef In C keyword is used to define a new name for an existing data type. It works as a type alias, providing a more descriptive or simplified name for complex declarations.
🌐
OpenGenus
iq.opengenus.org › typedef-struct-in-c
typedef struct in C [Explained]
December 5, 2022 - At the same time that you declare a variable of structure type, you can set the initial value of each of its members. The initial value of each member is enclosed in { } and becomes the value of each member in the order in which the structure is defined. Hence, the typedef keyword helps user to provide meaningful names to the already existing data types in the C language and make it more understandable for others as well.
🌐
GameDev.net
gamedev.net › home › forums › for beginners › c programing: using "struct" and "typedef struct"
c programing: using "struct" and "typedef struct" - For Beginners | GameDev.net Forums - GameDev.net
October 3, 2002 - For example, the following statements define coord as a synonym for the indicated structure: typedef struct { int x; int y; } coord; You can then declare instances of this structure using the coord identifier: coord topleft, bottomright; Note that a typedef is different from a structure tag, as described earlier in this chapter.