This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TMS320F280049C:类成员函数指针数据的实际内容

Guru**** 2795065 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1622143/tms320f280049c-actual-content-of-class-member-function-pointer-data

器件型号: TMS320F280049C

大家好!

我有一个非常详细的问题、因为我们在使用函数指针时偶然发现了这个问题。 正如预期的那样、常规函数指针被处理为 2 个字/32 位值。 使用成员函数指针时、指针的大小会增加到 4 个字。 我们已经可以看到、第二部分用于虚拟函数指针、如果是常规函数、则为 0;如果是虚拟函数、则为 1。 如果它是一个虚拟函数、则指针本身不包含函数地址、而只包含 vtable 内的偏移量(根据我们的理解)。

可能有许多方法可以展示它、但下面是一种理解我的意思的方法:

class T_Test
{
public:
    int32_t m_a;

    int32_t add(int32_t b);
    virtual int32_t sub(int32_t b);

    typedef int32_t (T_Test::*FunctionPointer)(int32_t);
};


int32_t T_Test::add(int32_t b) {return m_a+b;};
int32_t T_Test::sub(int32_t b) {return m_a-b;};

int main(void)
{
    T_Test TestInstance;
    T_Test* TestInstancePointer = &TestInstance;

    TestInstance.m_a = 10;

    T_Test::FunctionPointer pfuncAdd = &T_Test::add;
    T_Test::FunctionPointer pfuncSub = &T_Test::sub;

    int32_t arrAdd[sizeof(pfuncAdd)/2];
    memcpy((void*) arrAdd, (void*) &pfuncAdd, sizeof(pfuncAdd));

    int32_t arrSub[sizeof(pfuncSub)/2];
    memcpy((void*) arrSub, (void*) &pfuncSub, sizeof(pfuncSub));


    __asm(" ESTOP0");
}

其中大部分内容已经很清晰、但成员函数指针的第二个双字中是否存储了其他内容? 是否对此有任何详细说明?

我在“C28x 嵌入式应用程序二进制接口“sprac71b 或我找到的任何其他文档中找不到任何详细信息。 如果有一个,我很高兴的暗示。

此致
Wolfgang

 

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    是否对此有任何详细说明?

    不在 TI 文档中。  请对术语  c++虚拟功能表执行互联网搜索。 搜索返回的文章很可能有用。

    谢谢。此致、

    -乔治