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.

[参考译文] AM2434:发出 UINT32至 float32类型转换

Guru**** 2422790 points


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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1272183/am2434-issue-of-uint32-to-float32-type-conversion

器件型号:AM2434

我使用的是 TI ARM clang v2.1.LTS。

以下代码是根据 SDK 8.4.0.17示例代码修改的。

在 IdleLoop ()中,当我使用 UINT32指针"pTestResult"指向数组中奇数位置的地址,然后将 UINT32指针的值分配给全局 float32变量时,程序崩溃。

#include <stdlib.h>
#include "ti_drivers_config.h"
#include "ti_board_config.h"

void empty_main(void *args);
void IdleLoop( void );

Uint16 TestData[8] = {0x0000,0x0001,0x0002,0x0003,0x0004,0x0005,0x0006,0x0007};
Uint32 *pTestResult;
Uint32 PointerAddr;
Float32 TestResultFloat = 0.0f;

int main()
{
    System_init();
    Board_init();

    for(;;) {
        IdleLoop();
    }

    empty_main(NULL);

    Board_deinit();
    System_deinit();

    return 0;
}

void IdleLoop( void ) {
    void *pTest;

    pTest = (void *)&TestData[3];
    pTestResult = (Uint32 *)pTest;

    PointerAddr = pTestResult;

    TestResultFloat = *pTestResult;
}

将 UINT32指针的值分配给全局 float32变量时有什么问题?

谢谢