Skip to content

Commit

Permalink
Merge pull request #6 from yuhan2680/main
Browse files Browse the repository at this point in the history
Translate 02 and 03 in function folder
  • Loading branch information
Alumopper authored Jun 4, 2024
2 parents 10f7094 + b98d5d2 commit db780ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions docs/en/quickstart/04function/02static-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
lastUpdate: true
---

# static关键字
# static keyword

`static`关键字用于声明一个静态参数。静态参数表示,在参数传递的过程中,是传递的参数本身而不是参数的值,因此在函数中对参数的修改会影响外部的变量。例如:
`static` keyword used to define a static parameter. Static parameter represents, during the process of transferring parameter, it’ll transfer parameter itself but not it’s value, so the change of parameter in the function would effect the variable out of the function. For example:

```mcfpp
func test(static int a){
Expand All @@ -14,6 +14,6 @@ func test(static int a){
void main(){
int a = 0;
test(a);
print(a); #输出5
print(a); #output 5
}
```
18 changes: 9 additions & 9 deletions docs/en/quickstart/04function/03inline-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
lastUpdate: true
---

# 内联函数
# Inline function

MCFPP中,可以使用`inline`关键字来声明一个内联函数。编译器会在调用内联函数的地方直接将函数的代码插入,而不是通过函数调用的方式来执行。这样可以减少函数调用的开销,提高程序的运行效率。
In MCFPP, we can use keyword `inline` to declare an inline function. When call this function, compiler will insert the code into the code directly, but not call the function. So it can reduce the cost of calling functions, make the program more efficient.

## 内联函数的声明
## Declare of inline function

内联函数的声明语法如下:
The grammar of declare a inline function is:

```mcfpp
inline func functionName(parameter1, parameter2, ...) -> returnType{
#函数体
#Function body
}
```

## 内联函数的调用过程
## Call of inline function

在调用内联函数的地方,编译器会直接将内联函数的代码插入,而不是通过函数调用的方式来执行。例如下面的例子:
In the place of calling inline function, compiler will insert the inline function directly, but not call the function. Such as the example below:

```mcfpp
inline func add(int a, int b) -> int{
Expand All @@ -30,7 +30,7 @@ func main(){
}
```

编译的时候,上述代码会相当于:
During compilation, the code is same as:

```mcfpp
func main(){
Expand All @@ -41,4 +41,4 @@ func main(){
}
```

这同时意味着,在内联函数中,对变量的修改会影响到函数外部的变量。
This means that, in the inline function, the change to variable will effect the variable out of the function.

0 comments on commit db780ae

Please sign in to comment.