1. struct
A struct is a composite data type whose constituent elements can be composite data types, such as Array,struct,union, by default, the compiler assigns space to each member of the struct by its natural alignment (by default, by the size of the largest member in the struct member). The first member and the entire struct address are the same.
Using the pseudo-directive #pragma pack (n), the compiler will align N bytes, and if n is greater than the maximum member size in the struct, the struct is thrown to align with the largest member of size.
2, the role of the static keyword
In the body of a function, a variable declared as static maintains its value in the process of the function being called.
Within the function body of the module, a variable declared as static can be accessed by all functions within the module and cannot be accessed by other functions outside the module, which is a local global variable
Within the module, a function declared as static can only be called by other functions of this module
3, the meaning of the const keyword
4, volatile has what meaning
A volatile modified variable can be unexpectedly changed, so each access is re-reading the value of the variable instead of using the backup stored in the register. For example, hardware registers for parallel devices, non-automatic variables that are accessed in an interrupt service subroutine, variables shared by several tasks in a multithreaded application
2, C high-efficiency programming
The first trick: to space for time, such as function calls need to press stack and out of the stack operation, if the macro, although the use of a lot of space, but the consumption of CPU time reduced
The second trick: mathematical methods to solve problems, such as: I= (100* (1+100))/2 (for 1~100 and)
The third trick: using bit operations, for example: j = 456%32 operation can be replaced by: j = 456-(456>>4<<4);
Four strokes: Assembler embedding
Note:
1. Position operation function:
#define BWMCDR2_ADDRESS 4
#define Bsmcdr2_address 17
#define Bmmcdr2_address Bit_mask (mcdr2_address)
#define BIT_MASK (_BF) (((1u<< (bw# #_bf)-1) << (bs# #_bf)
#define SET_BITS (_dst,_bf,_val) ((_DST) = ((_DST) &~ (Bit_mask (_BF))) | ( ((_val) << (bs# #_bf) &bit_mask (_BF))))
Set_bits (Mcdr2,mcdr2_address,registernumber)
C Study Notes