小编Phi*_*ppe的帖子

用std :: cout正确地用0填充负整数

我发现这个问题已经问到了,但每个人给出的答案都是

std::cout << std::setw(5) << std::setfill('0') << value << std::endl;
Run Code Online (Sandbox Code Playgroud)

这对于正数很好,但是对于-5,它会打印:

000-5
Run Code Online (Sandbox Code Playgroud)

有没有办法让它打印-0005或强制cout始终打印至少5位数(这将导致-00005),因为我们可以用printf做?

c++ iostream cout iomanip

12
推荐指数
1
解决办法
1383
查看次数

调试haskell中的堆栈溢出

我是Haskell和函数式编程的新手,我有一个程序可以工作但几秒后就会溢出堆栈.我的问题是,我该怎么做?我怎样才能至少得到它出现的位置,打印堆栈或其他什么?

使用以下命令在ghci中运行时程序非常慢:跟踪不会发生堆栈溢出.runhaskell也不会出现这种情况,只会占用越来越多的内存.我只在用ghc编译并执行时才得到错误.

stack-overflow debugging haskell

8
推荐指数
1
解决办法
870
查看次数

防锈功能没有静态寿命?

我正在尝试使这个简单的代码编译:

fn dox(x: u8) -> u8 { x*2 }

fn main() {
    let cb: &'static (Fn(u8) -> u8) = &dox;
}
Run Code Online (Sandbox Code Playgroud)

但它失败了Rust 1.9:

x.rs:4:40: 4:43 error: borrowed value does not live long enough
x.rs:4     let cb: &'static (Fn(u8) -> u8) = &dox;
                                              ^~~
note: reference must be valid for the static lifetime...
x.rs:4:44: 5:2 note: ...but borrowed value is only valid for the block suffix following statement 0 at 4:43
x.rs:4     let cb: &'static (Fn(u8) -> u8) = &dox;
x.rs:5 …
Run Code Online (Sandbox Code Playgroud)

lifetime rust

8
推荐指数
2
解决办法
644
查看次数

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
查看次数

是否可以在catch子句中进行co_await?

如下代码:

try {
  throw 42;
} catch (int i) {
  co_await somefuture;
}
Run Code Online (Sandbox Code Playgroud)

用-fcoroutines-ts用clang 6和7编译。但是,它无法与Visual C ++ 15(2017)Visual C ++ 16(2019)一起使用/ await编译并出现错误

C2304:不能在catch块内使用'co_await'

C ++ 20标准草案和cppreference似乎没有提及任何内容。

它是Microsoft编译器中缺少的功能,还是我误解了该标准?

c++ c++20 c++-coroutine

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

如何在不复制它们的情况下对一对借来的值使用匹配?

我将我的问题减少到以下代码:

enum E {
    E1,
}

fn f(e1: &E, e2: &E) {
    match *e1 {
        E::E1 => (),
    }
    match (*e1, *e2) {
        (E::E1, E::E1) => (),
    }
}

fn main() {}
Run Code Online (Sandbox Code Playgroud)

第一场比赛没问题,但第二场比赛无法编译:

error[E0507]: cannot move out of borrowed content
 --> src/main.rs:9:12
  |
9 |     match (*e1, *e2) {
  |            ^^^ cannot move out of borrowed content

error[E0507]: cannot move out of borrowed content
 --> src/main.rs:9:17
  |
9 |     match (*e1, *e2) {
  |                 ^^^ cannot move out of borrowed …
Run Code Online (Sandbox Code Playgroud)

rust

0
推荐指数
1
解决办法
326
查看次数

标签 统计

c++ ×2

rust ×2

android ×1

arm ×1

c ×1

c++-coroutine ×1

c++20 ×1

cout ×1

debugging ×1

elf ×1

haskell ×1

iomanip ×1

iostream ×1

lifetime ×1

loader ×1

stack-overflow ×1