I have seen many Embedded C knowledge points on the Internet, and I always want to accumulate them. The so-called non-accumulation of small streams can not become a river, without accumulation of steps and even thousands of miles.
1. # define senconds_per_year (60*60*24*365) UL
1) macro definition syntax, format
2) intuitively express the meaning of this number (How many seconds a year)
3) This number will cause a 16-bit server to overflow. The long integer L and the unsigned number are required, so ul is used.
2. # define min (A, B) (a) <= (B )? (A) (B ))
1) the triple-condition operator will make the compiler generate code that is more optimized than if-than-Else. Note that inline can also generate embedded code.
2) parameters in the macro must be enclosed in parentheses.
3) leaset = min (* P ++, a); what errors does this statement produce?
The operation Priority of ++ is higher than that of *. Therefore, the address ++ is used first, and then the value is taken to obtain uncertain results.
3. pre-processor representation # What is error?
1) a wide range of applications. During the preprocessing phase, preprocessing errors are generated and custom errors are output.
# Error [custom error messages]
For example, if the compiling environment is detected to be a C ++ reminder, you need to run it in the C compiling environment.
4. Infinite Loops)
I am used to using while (1) {}, and the structure looks clear at a glance. In addition, a variable = 1 can be defined, and the variable name can be written as an infinite loop running condition, so that the purpose of this loop can be seen at a glance.
Of course, some people like for (;) {}, and there is no problem.
5. variable definition
A) An integer)
B) a pointer to an integer (a pointer to an integer)
C) a pointer to a pointer pointing to an integer (a pointer to an integer)
D) an array of 10 integers (an array of 10 integers)
E) an array with 10 pointers pointing to an integer (an array of 10 pointers to integers)
F) A pointer to an array with 10 integers (a pointer to an array of 10 integers)
G) a pointer to a function. The function has an integer parameter and returns an integer number (a pointer to a function that takes an integer as an argument and returns an integer)
H) An array with 10 pointers pointing to a function, this function has an integer parameter and returns an integer (an array of ten pointers to functions that take an integer argument and return an integer)
Answer:
A) int_t;
B) int_t *;
C) int_t **;
D) int_t A [10];
E) int_t * A [10];
F) int_t (* A) [10 };
G) int_t (* A) (int_t );
H) int_t (* A [10]) (int_t );
6. Static Functions
1) static variables and functions are stored in the static storage area and initialized at the beginning of the program. Unique initialization. The static variable value can be changed. The address is initialized at the beginning.
2) static variables and static functions can only be called by functions in the module.