More about C types in AVR-GCC

Char types

As it is important to understand variable types in AVR-GCC lest take a deeper look at this.

Choosing proper variable type sometimes may be crucial in designing embedded software as microcontroller resources are limited. Choice of proper variable type may save lots of time and space of your program.

What is common variable type in 8 bit system? Of course byte or so called char type. Char name comes from word “character” because char type usually is used to store character symbols (ASCII). Char type can have values from -128 to +127 while unsigned char may have values from 0 to 255 256. Some compilers may use byte type instead of unsigned char.

User types

C language allows defining user types. For this typedef keyword is used:

typedef unsigned char byte; //create byte type

typedef unsigned int word; //create word type

In other words defining custom types description structure is used:

typedef standard_type custom_type;

WinAVR compiler has predefined custom types:

typedef signed char int8_t; //located in header file inttypes.h

typedef unsigned char uint8_t; //located in header file inttypes.h

typedef int int16_t; //located in header file inttypes.h

typedef unsigned int uint16_t; //located in header file inttypes.h

typedef long int32_t; //located in header file inttypes.h

typedef unsigned long uint32_t; //located in header file inttypes.h

typedef long long int64_t; //located in header file inttypes.h

typedef unsigned long long uint64_t; //located in header file inttypes.h

typedef struct {int quot; int rem} div_t; //located in header file stdlib.h. It is used for standard function ldiv();

Comments

A byte can have a value between 0 and 255. 256 would be the value of the 9th bit.