1KW-8KW Power Inverter
Use double MCU design,the product provides different charge voltages and charge currents to realize charge management for batteries of different types.Its mains supply preferred mode,energy--saving mode and battery preferred mode are all settable,thus making it easy to meet users' different application needs.It has an LCD to show operation status.It is widely applied to families,schools,streets,frontier defense,pasturing areas,industrial equipment,military vehicle--borne equipment,ambulances,police cars,ships,ect.
Nkm Hybrid Inverter With Mppt Charge,Inverter Power Inverter,Hybrid Inverter Charger,Hybrid Grid Tie Inverter suzhou whaylan new energy technology co., ltd , https://www.xinlingvideo.com
Macro definition analysis of formal and actual parameters in c language
C language supports macros with parameters. In a macro definition, the parameters are called formal parameters, while in a macro call, they are referred to as actual parameters. This is somewhat similar to function calls, but instead of passing values, macros perform text substitution during preprocessing.
When a macro with parameters is called, the actual parameters are substituted for the formal ones in the macro body. The general form of a parameterized macro definition is:
```
#define macro_name (parameter_list) string
```
The `string` contains the formal parameters, which will be replaced by the actual arguments when the macro is used. The general form of a macro call is:
```
macro_name(argument_list);
```
For example:
```c
#define M(y) y*y + 3*y
```
In this case, when `M(5)` is called, it expands to `5*5 + 3*5`. The actual value replaces the formal parameter `y`.
Another example is the `MAX(a, b)` macro, which returns the larger of two numbers:
```c
#include
#define MAX(a,b) (a > b) ? a : b
int main() {
int x, y, max;
printf("Input two numbers: ");
scanf("%d %d", &x, &y);
max = MAX(x, y);
printf("max=%d\n", max);
return 0;
}
```
After preprocessing, the line `max = MAX(x, y);` becomes `max = (x > y) ? x : y;`.
There are some important rules to follow when defining macros with parameters:
1. **No space between macro name and parameter list**: For example, `#define MAX(a,b) ...` is correct, but `#define MAX (a,b) ...` would define a macro without parameters, leading to incorrect expansion.
2. **No data types required for formal parameters**: Since macros are expanded at compile time, there's no need to declare data types for the formal parameters. However, the actual parameters must have valid data types.
3. **Parentheses around parameters and expressions**: It is crucial to enclose both the parameters and the entire expression in parentheses to avoid unexpected behavior due to operator precedence. For instance:
```c
#define SQ(y) (y) * (y)
```
If parentheses are omitted, the macro may produce incorrect results. Consider the following example:
```c
#define SQ(y) y * y
```
If `SQ(a + 1)` is called, it expands to `a + 1 * a + 1`, which evaluates incorrectly due to operator precedence. To fix this, always use parentheses:
```c
#define SQ(y) ((y) * (y))
```
This ensures that the entire expression is evaluated correctly, even when used in more complex contexts like `200 / SQ(a + 1)`.
In summary, macros with parameters provide a powerful way to write reusable code, but care must be taken with their usage to avoid subtle bugs caused by improper substitution or missing parentheses. Unlike functions, macros do not involve function calls or memory allocation; they are simply text replacements performed by the preprocessor.