小编sbw*_*sbw的帖子

__cdecl 调用约定不适用于 msvc x64

__cdecl只是对调用约定的测试。

这是一个 cmake 项目,只有 1 个源文件:

#include <stdio.h>

#define CALL_CONVENTION __cdecl

void CALL_CONVENTION f(int a, int b)
{
    printf("%d, %d", a, b);
}

int main()
{
    f(1, 2);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我用来set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /FA")输出汇编代码。

当我使用 构建时cmake -G "Visual Studio 15",它构建了一个 32 位应用程序,并且一切都在预期中:

...
; Line 12
    push    ebp
    mov ebp, esp
; Line 13
    push    2        ; <------- argument 2
    push    1        ; <------- argument 1
    call    _f       ; <------- call function
    add esp, 8 …
Run Code Online (Sandbox Code Playgroud)

c++ windows calling-convention visual-c++

3
推荐指数
1
解决办法
2075
查看次数

返回本地String作为选项<&str>

我想编写一个接收&str参数并返回的函数Option<&str>.我写了这个:

fn f(text: &str) -> Option<&str> {
    if // some condition {
        return None;
    }

    let mut res = String::new();
    // write something into res.

    // return res
    Some(&res[..])
}
Run Code Online (Sandbox Code Playgroud)

但是我收到一个错误:

res 活得不够久.

解决这个问题的最佳解决方案是什么?

rust

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

标签 统计

c++ ×1

calling-convention ×1

rust ×1

visual-c++ ×1

windows ×1