问题标签 [function-pointers]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
7 回答
295442 浏览

c - 了解 C 中函数指针的 typedef

当我阅读其他人的代码时,我总是有点难过,这些代码有 typedef 用于指向带参数的函数的指针。我记得在尝试理解前一段时间用 C 编写的数值算法时,我花了一段时间才找到这样的定义。那么,您能否分享您关于如何为函数指针(Do's 和 Do's)编写好的 typedef 的技巧和想法,以及它们为什么有用以及如何理解其他人的工作?谢谢!

0 投票
2 回答
2546 浏览

c - 如何将函数指针传递给具有可变参数的函数?

我不知道如何做到这一点!
如何在 va_list 参数中获取函数指针?
非常感谢。

0 投票
1 回答
123 浏览

.net - Is it possible to infer that a ParameterInfo object refers to a function pointer containing managed parameter types?

I'm using reflection to examine the following method declaration and am wondering if it is possible to determine that the method's sole parameter is a function pointer.

When inspecting the ParameterInfo object for foo's parameter, it shows that the parameter's type is IntPtr; this makes sense since a function pointer is not a native CLR type.

Since the function pointer contains only managed parameter types, I was hoping to get some extra context in the ParameterInfo. I don't see any properties or attributes in ParameterInfo and Type that may help me distinguish this IntPtr instance as a function pointer -- are there any?

0 投票
8 回答
447 浏览

c - 为什么在 C 中出现警告而无法在 C++ 中编译?

为什么这段代码

在 C 中,编译时给我这样的警告:

'警告:来自不兼容指针类型的赋值'

在 C++ 中,无法编译。

0 投票
4 回答
1004 浏览

c - 将任意结构指针数组传递给C函数?

我想将任意结构指针数组和比较函数传递给通用排序算法。这在C中可能吗?

结构的goooeys只能在比较函数中访问,排序函数只需要调用比较函数和交换指针,但我不知道如何声明它。

0 投票
5 回答
1957 浏览

c - 函数声明中的函数指针是否有 C 语法

除了为函数声明函数指针 typedef 之外,是否可以从函数声明中获取它?

通常,

我想要的是:

我想将它用于 dlsym:

如果我更新 foo 却忘记更新 fooFunc,反之亦然,那将很糟糕。另外,我可能有很多函数,维护函数声明和与这些函数关联的函数指针类型定义会更费力。

结论:AndreyT 的答案是最便携的,但如果您为 gcc 编写代码,那么 typeof 是一个很好的解决方案。

0 投票
5 回答
649 浏览

c++ - c++: &rand 到底是做什么的?

这是一些 c++ 代码的摘录,我将不得不在某些日子里详细解释:

我想我了解它的一切,除了那个小小的神秘&rand。它到底是做什么的?我的意思是显然它会产生某种伪随机数,但它们总是保持不变。&rand 是从哪里来的?它是一种什么样的表达方式?它产生的价值从何而来?我有点困惑……</p>

此外,我在代码中找不到任何其他出现的“rand”一词,也没有看到任何可能与随机数有关的代码。这让我想知道,因为我在 c++ 方面的(非常有限的)经验表明,只有很少的东西可以简单地工作而无需事先声明或包含。

感谢您的帮助!

0 投票
6 回答
815 浏览

c++ - 你能解释一下下面的 C/C++ 语句吗?

0 投票
4 回答
1780 浏览

java - 迭代函数

在Java中可以做这样的事情吗?

我只调用了几个函数,但我需要编写它们,如下所示:

而且我想避免写出数百行函数调用。

我试过研究函数指针和仿函数,但没有找到任何相关的东西。

0 投票
2 回答
2823 浏览

c++ - 私有成员函数,它接受指向同一类中私有成员的指针

我怎样才能做到这一点?(以下代码不起作用,但我希望它能解释这个想法。)

我想以某种方式调用 Caller,例如:

并使用它认为需要传递的任何参数进行Caller调用。ToBeCalled如果可能的话,我希望将所有内容都封装在我班级的私有部分中。实际上,我有大约 50 个类似的函数ToBeCalled,所以我看不到避免这种情况的方法。

感谢您的任何建议。:)