[英]difference between calling a function when it is pointed by a pointer and not pointed by a pointer
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 指示符用于表达式而不是sizeof
或unary &
的操作数时,它会自动转换为指向 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.) (如上所述,虽然
foo
在foo();
中使用,但它会自动转换为地址,就好像(&foo)();
已被写入。所有 function 调用实际上使用 function 的地址,即使 function 指示符是用过的。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.