Course contentsShow
← C
Lesson 612 of 1,2199. Structures and UnionsFree lesson

Naming conventions for typedef types

Naming conventions for typedef types

What you'll learn: How to name your custom types clearly so they stand out from standard variables and built-in keywords.

When you use typedef, you are essentially giving a nickname to a complex data type. However, if you name your new type user, and then name a variable user later in your code, the compiler (and your brain) might get very confused. To keep your code professional and readable, programmers follow specific naming conventions to distinguish "blueprints" (types) from "actual things" (variables).

The "Suffix" approach

One of the most popular conventions in C is adding a _t suffix to your type names. The t stands for "type." This makes it immediately obvious that the word isn't a variable name. Many standard C types use this, such as size_t or uint32_t.

typedef struct {
    int id;
    float balance;
} Account_t;

// Usage:
Account_t myAccount; 

In this example, Account_t is the blueprint, and myAccount is the actual data. The _t acts like a label on a folder, telling you "this is a category, not a specific item."

The "PascalCase" approach

Another common style, borrowed from languages like C++ and Java, is PascalCase. This means capitalizing the first letter of every word and using no underscores. Because standard C variables usually start with lowercase letters (my_variable), a capitalized name signals that you are looking at a custom-defined type.

typedef struct {
    int x;
    int y;
} Point;

// Usage:
Point startCoordinate;

Why consistency matters

Think of your code like a kitchen. If you label a jar "Flour" (the type) and another jar "CurrentFlour" (the variable), you always know which is which. If you just labeled everything "flour," you’d constantly be second-guessing your recipes.

Whichever style you choose—whether it is Account_t or Account—the golden rule is to pick one and stick to it throughout your entire project. Mixing styles makes the code look messy and harder for other developers to follow.

Key takeaway

Use a consistent naming style like PascalCase or a _t suffix for typedef names to clearly separate type definitions from variable names.