每篇文章都说.init_array部分是一个函数数组,但根据我的经验,它不是.
这是我为Android编译的libc.so的.init_array:
$ prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-objdump -s -j .init_array out/target/product/e910/obj/SHARED_LIBRARIES/libc_intermediates/LINKED/libc.so
out/target/product/e910/obj/SHARED_LIBRARIES/libc_intermediates/LINKED/libc.so: file format elf32-littlearm
Contents of section .init_array:
42000 e1620100 ffffffff 75940200 00000000 .b......u.......
Run Code Online (Sandbox Code Playgroud)
它包含4个字(小端):
000162e1
ffffffff
00029475
00000000
Run Code Online (Sandbox Code Playgroud)
000162e1并且00029475看起来像一些函数指针:
000162e0 <__libc_preinit>:
* as soon as the shared library is loaded.
*/
void __attribute__((constructor)) __libc_preinit(void);
void __libc_preinit(void)
{
162e0: b510 push {r4, lr}
* Note that:
* - we clear the slot so no other initializer sees its value.
* - __libc_init_common() will change the TLS area so the …Run Code Online (Sandbox Code Playgroud) 给定任何函数(或可调用)类型
Function,如何将其所有参数类型作为元组类型?
例如,我需要一个trait function_traits<Function>::arguments,其中:
int f();
typename function_traits<decltype(f)>::arguments // => gives me std::tuple<>
void g(int);
typename function_traits<decltype(g)>::arguments // => gives me std::tuple<int>
void h(int, int);
typename function_traits<decltype(h)>::arguments // => gives me std::tuple<int, int>
Run Code Online (Sandbox Code Playgroud)
我需要获取参数的大小,幸运的是boost已经实现了 function_traits<F>::arity
生成一个std::integer_sequence从1来进行构图,将其映射到参数类型,但是问题出在map integer_sequence,我需要这样的东西:
function_traits<F>::arg_type<N> // -> N-th arg_type
Run Code Online (Sandbox Code Playgroud)
但是boost仅提供以下功能:
function_traits<F>::argN_type
Run Code Online (Sandbox Code Playgroud)
我该如何实施function_traits<F>::arg_type<N>?我最多可以使用c ++标准到c ++ 17
c++ templates variadic-templates template-argument-deduction c++17
如何定义类型InfiniteFunction,它是一个函数,调用时返回另一个InfiniteFunction
类型看起来像:
() => () => () => ... // infinite
Run Code Online (Sandbox Code Playgroud)
或递归:
type InfiniteFunction = () => InfiniteFunction
Run Code Online (Sandbox Code Playgroud)
这不起作用
scala> type InfiniteFunction = () => InfiniteFunction
<console>:11: error: illegal cyclic reference involving type InfiniteFunction
type InfiniteFunction = () => InfiniteFunction
Run Code Online (Sandbox Code Playgroud)
我想在此功能上进行cps转换:
def travel(tree: TreeNode): Unit = {
if (tree != null) {
travel(tree.left)
println(tree.value)
travel(tree.right)
}
}
Run Code Online (Sandbox Code Playgroud)
在cps之后:
def r[T](f: => T): () => T = () => f
def travel(tree: TreeNode, cb: () => AnyRef): …Run Code Online (Sandbox Code Playgroud)