Date: agosto 25, 2025
Author: Guillermo Garcia
Categories: Embedded C programming Tags: Embedded C programming
In this article we will see the typedef allows us to create a special data type defined by the programmer and is widely used in C programs for embedded systems.
Table of Contents
In C it is possible to create an alias for a previously defined type. To avoid using complex type names, which is the case for enumeration types, you can define your own self explaining aliases using the
keyword typedef.
typedef int INTEGER;
defines INTEGER as an alias for the type int. The new type INTEGER can be used instead of the standard type int:
INTEGER counter, size;
The above declaration reserves memory for the 2 variables counter and size that are of the type INTEGER or int.
The typedef can be used to create structure-type data types and thus access a variable of a type specified by the programmer more clearly and efficiently. This will give the flexibility to manage memory more efficiently as the program requires.
typedef struct{
int number;
char description[30];
int inventory;
float purchase;
float retail;
}Product;
Product art1, art2, art[100];
The enum can be used to create enumeration data types, which allows you to create lightweight data types to make code structure clearer.
typedef enum days { Sun, Mon, Tue, Wed, Thu, Fri, Sat } Day;
An enum in C is a way to define sets of integer constants with symbolic names, which makes programming easier and the code more understandable.
Key Features
✅ They’re basically integers, but with clearer names.
✅ They improve code readability and maintainability.
⚠️ They’re not strictly type-safe → other integers can be assigned directly.
The enum list itself doesn’t take up any memory. A variable declared with that type does take up memory, usually the same as an int (usually 4 bytes).
Yes, enums in C take up memory space, because at the end of the day the compiler treats them as integers (int).

Deja una respuesta