简体   繁体   English

当它被指针指向时调用 function 和不被指针指向时的区别

[英]difference between calling a function when it is pointed by a pointer and not pointed by a pointer

may I know what are the differences in the way the function foo is being called here:我可以知道这里调用 function foo 的方式有什么不同吗:

在此处输入图像描述

In (1), main calls go and passes the address of foo in the call.在(1)中, main调用go ,并在调用中传递了foo的地址。 In (2), main calls go and does not pass any argument.在 (2) 中, main调用go并且不传递任何参数。 ( foo designates the function foo . However, when a function designator is used in an expression other than as the operand of sizeof or of unary & , it is automatically converted to a pointer to the function. So go(foo) is equivalent to go(&foo) .) foo指定 function foo 。但是,当 function 指示符用于表达式而不是sizeofunary &的操作数时,它会自动转换为指向 function 的指针。所以go(foo)等同于go(&foo) 。)

In (1), go takes a parameter that is a pointer to a function with unspecified parameters and return type void .在 (1) 中, go接受一个参数,该参数是指向 function 的指针,具有未指定的参数和返回类型void In (2), go does not take any parameters. (2)中, go不带任何参数。

In (1), go calls the function whose address it was passed, by using its parameter proc .在 (1) 中, go通过使用其参数proc调用传递给其地址的 function。 In (2), go calls foo .在 (2) 中, go调用foo (As above, although foo is used in foo(); , it is automatically converted to an address, as if (&foo)(); had been written. All function calls actually use the address of the function, even if function designator is used.) (如上所述,虽然foofoo();中使用,但它会自动转换为地址,就好像(&foo)();已被写入。所有 function 调用实际上使用 function 的地址,即使 function 指示符是用过的。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM