cbyte

how to create a new type with custom bytes in C?


Is it possible to create a new type in C that uses the amount of bytes that I decide? I know that an int takes 4 bytes, but I need to work with very small numbers so allocating 4 bytes with malloc for every int is a bit of a waste, i was thinking of creating a new type for numbers that takes only 1 byte...if it's possible


Solution

  • You can just use char instead of int

    Or, you can create structure, it is the most commonly used custom data type in C. For example:

    struct customStructure {
        char c;
    };