This recipe illustrates a version of addTwoNums
that uses the machine storage classes, int32_t
and uint8_t
. We explain why it is advantageous for embedded applications to define and use these as opposed to the primitive types that are provided by the C language.
To define and use machine storage classes, please follow the outlined steps:
Create a new folder named
addTwoNums_v2
by cloning the previous project.Copy the
addTwoNums.c
file from the previous recipe to the folder and modify it as follows:int main (void) { int32_t input; uint8_t num1, num2, res; HAL_Init (); /* Init Hardware Abstraction Layer */ SystemClock_Config (); /* Config Clocks */ SER_Init(); for (;;) { /* Loop forever */ printf("Enter First Number: "); scanf("%d", &input); num1 = (uint8_t) input; printf("Enter Second Number: "); scanf("%d", &input); num2 = (uint8_t) input; res = num1...