[mw_shl_code=c,true]
#include "stdint.h"
// 命令结构体
typedef struct _Command_Block
{
uint8_t eCommandType;
uint8_t Databuf[64];
}Command_Block_t;
//试运行命令 数据类型
typedef struct _TestRun_CmdData
{
uint8_t Test_Mode; // 1 模式
uint8_t Test_Run; // 1 开始测试
double Speed; // 速度
}Test_Run_CmdData_t;
// 主程序
void test_main(void)
{
Command_Block_t NewCommand;
Test_Run_CmdData_t* NewCmd; // 主要是想将NewCmd 指向 NewCommand.Databuf
NewCmd = (Test_Run_CmdData_t*)&NewCommand.Databuf[0]; //指针指Databuf存
NewCmd->Test_Mode = 1;
NewCmd->Test_Run = 1;
NewCmd->Speed = 0.05; // 这里会跳入 HardFault_Handler
if(NewCmd->Test_Run == 0)
return;
}[/mw_shl_code]
1.请问问题出在那里????
2.如果我把uint8_t Databuf[64];数组替换为uint8_t* Pbuf 。Pbuf初始化的时候指向一个全局数组变量Cmd[64]。再执行下面的操作就不会出问题。 这个又是什么原因???
[mw_shl_code=c,true][/mw_shl_code]
|