相关疑难解决方法(0)

x86-64上的C++:何时传递结构/类并在寄存器中返回?

假设Linux上的x86-64 ABI,在C++中的什么条件下结构传递给寄存器中的函数而不是堆栈中的函数?他们在什么条件下返回登记册?课程的答案是否会改变?

如果它有助于简化答案,则可以假设单个参数/返回值而没有浮点值.

c++ assembly x86-64 abi

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

存储的返回值在哪里?

我知道用C编码,函数的返回值使用%eax寄存器返回给调用者.

使用c ++,也可以返回结构而不仅仅是'Primitive'类型,所以当一个函数返回一个结构时,存储的返回值在哪里(堆栈,堆等)?

示例代码:

class Student
{
private:
    int m_id;
public:
    Student(int id)
    {
        m_id = id;
    };
    ~Student();
    int getId()
    {
        return m_id;
    };
};

Student myFunc()
{
    return Student(123);
}

int main()
{
    //How does 'student1' get the value from the function?
    //Does 'myFunc' write directly to the stack of main?
    Student student1 = myFunc();


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

c c++

6
推荐指数
1
解决办法
258
查看次数

__cdecl 调用约定如何返回结构体?

我想调用一个返回 a 的函数struct,这个函数有__cdecl调用约定。

调用约定如何__cdecl返回 a struct

x86 assembly nasm

2
推荐指数
1
解决办法
1777
查看次数

函数如何在不使用 malloc 的情况下返回结构?

我是 C 新手,只是一个关于返回结构的问题。我听到有人说可以返回一个结构体。例如:

struct MyObj{
   int x,y,z;
};

struct MyObj foo(){
    struct MyObj foo_a;
    foo_a.x = 10;
    foo_a.y = 10;
    foo_a.z = 10;

    return foo_a;
}        

int main () {
    struct MyObj main_a = foo();
    return 0;
} 
Run Code Online (Sandbox Code Playgroud)

我的问题是:

foo_afoo的堆栈,在经过这么foo结束,堆栈将unwinded,其手段foo_a实际上并不存在的main函数的栈指针main_amain持有实际上是一个非法的指针,那么它是怎么样的工作?

c struct allocation return-value

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

标签 统计

assembly ×2

c ×2

c++ ×2

abi ×1

allocation ×1

nasm ×1

return-value ×1

struct ×1

x86 ×1

x86-64 ×1