[英]What does this function definition mean?
This function definition is found here. 此功能定义可在此处找到。 :
:
static void (*resolve_memcpy (void)) (void)
{
return my_memcpy; // we'll just always select this routine
}
I don't understand what it means. 我不明白这意味着什么。
resolve_memcpy is a function taking no arguments and returning a pointer to a function taking no arguments and returning void. resolve_memcpy是一个不带参数的函数,并返回一个指向函数的指针,该函数不带参数并返回void。
EDIT: Here's a link where you can read more about this kind of syntax: http://unixwiz.net/techtips/reading-cdecl.html 编辑:这是一个链接,您可以在其中阅读有关此类语法的更多信息: http : //unixwiz.net/techtips/reading-cdecl.html
Here's my standard method for reading hairy declarations: start with the leftmost identifier and work your way out, remembering that absent any explicit grouping ()
and []
bind before *
: 这是我阅读毛茸茸声明的标准方法:从最左边的标识符开始并逐步解决,记住在
*
之前没有任何显式分组()
和[]
绑定:
resolve_memcpy -- resolve_memcpy
resolve_memcpy(void) -- is a function taking no arguments
*resolve_memcpy(void) -- and returning a pointer
(*resolve_memcpy(void)) (void) -- to a function taking no arguments
void (*resolve_memcpy(void)) (void) -- and returning void
static void (*resolve_memcpy(void)) (void) -- and is not exported to the linker
So the return value of the resolve_memcpy
function is a pointer to another function: 所以
resolve_memcpy
函数的返回值是指向另一个函数的指针:
void (*fptr)(void) = resolve_memcpy();
fptr(); // or (*fptr)(), if you want to be explicit
If you want to drive your coworkers insane, you could write 如果你想让你的同事疯狂,你可以写
resolve_memcpy()();
which will execute the function whose pointer is returned by resolve_memcpy
. 它将执行
resolve_memcpy
返回其指针的函数。
It basically returns a function pointer, which (presumably) you're supposed to use instead of memcpy
. 它基本上返回一个函数指针,(大概)你应该使用而不是
memcpy
。
// memcpy(...)
resolve_memcpy()(...) // Use this instead.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.