简体   繁体   English

这个函数定义是什么意思?

[英]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返回其指针的函数。

One can use cdecl to find: 可以使用cdecl查找:

declare resolve_memcpy as static function (void) returning pointer to function (void) returning void 将resolve_memcpy声明为static function(void)返回指向function(void)返回void的指针

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.

相关问题 这是什么意思:此处不允许在 '{' 标记之前使用函数定义 - What does this mean: a function-definition is not allowed here before '{' token “Class *&cls”在C ++的函数定义中意味着什么? - What does “Class* &cls” mean in C++'s function definition? 这种typedef定义是什么意思? - What does this typedef definition mean? 宏定义中的空#是什么意思? - What does an empty # mean in a macro definition? 这个模板定义在c ++中意味着什么? - what does this template definition mean in c++? Friend函数类内定义仅允许在非本地类定义中使用。 这是什么意思? - Friend function in-class definition only allowed in non-local class definitions. What does it mean? 什么C ++编译器错误“看起来像一个函数定义,但没有参数列表;”是什么意思? - What does the C++ compiler error “looks like a function definition, but there is no parameter list;” mean? 当你获得类声明的编译错误“看起来像一个函数定义”时,它意味着什么? - What does it mean when you get a compile error “looks like a function definition” for a class declaration? function 定义/实现的返回值的 scope 中的私有是什么意思(c++)? - What does private in the scope of the return value of a function definition/implementation mean (c++)? 这个宏功能是什么意思? - What does this macro function mean?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM