小编Zan*_*Jie的帖子

ELF二进制文件中的.init_array部分是什么?

每篇文章都说.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)

c android arm elf loader

5
推荐指数
1
解决办法
5956
查看次数

gcd的时间复杂度如何是Θ(logn)?

我在Interview Bit上解决了时间复杂度问题,如下图所示. 在此输入图像描述

给出的答案是?(theta)(logn),我无法掌握登录术语如何到达此计划的时间复杂性.

有人可以解释一下logn的答案是什么?

big-o time-complexity big-theta asymptotic-complexity greatest-common-divisor

5
推荐指数
1
解决办法
839
查看次数

获取函数参数类型为元组

问题

给定任何函数(或可调用)类型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

5
推荐指数
1
解决办法
116
查看次数

如何定义类型:无限函数?

如何定义类型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)

scala language-lawyer

4
推荐指数
1
解决办法
86
查看次数