Home > other >  Ask how to reduce the use of global variables in the stm32 code design?
Ask how to reduce the use of global variables in the stm32 code design?

Time:01-14

Application scenarios, for example: N1 - N10. A total of 10 c files, including N1. The structure of h Time_Struct defined as:
[code] typedef struct
{
Int Hour;
Int minute;
Char second;
}
TimeTypedef; [/code]

N1. C TimeStruct defines the variable;

N2 TimeStruct C need to read. The value of the Hour,
N3. C to TimeStruct. Minute (make sure to prevent their first reading),
N4 interchange. C to TimeStruct. Minute reduction (make sure to prevent their first reading),

The disposal methods for the variable I can think of the solution is as follows:
(1) global variable, extern way coupling is too strong, upgrade maintenance trouble, behind the main is extremely important, it is not recommended to use,
(2) write function, assignment or read through the participation, coupling can be effectively avoided, but if the program a complex, projects can have more than function, a lot of function to establish the purpose is to spread the refs,
(3) in other to use TimeStruct the N1. C file, through the way of registration (secondary pointer),

Given is bare, without what to the operating system can use the concept of process communication, don't know how to deal with as well, Posting mainly want to ask next everybody everyday when the design is how to deal with this demand? Thank you very much!

CodePudding user response:

Oneself the top

CodePudding user response:

1, make an own header files, the need to use the extern to declare variables function all throw into, such as
2, each involving the external variables and functions. C file to include the header file is ok,
  • Related