|
在 Visual Studio 里写 C++ 程序,编译通过后再移植到 STM32 CubeIDE。我写了一个简单的 for 循环, for(int z=5;z<15;z++) { cout<<"when z is equal to 10, the loop will be broken out\n"; if(z==10) { break; } cout<<z<<endl; } cout<<z<<endl; 运行后变量 z 在循环体外输出了奇怪的值:1971940899。 终端输出如下: when z is equal to 10, the loop will be broken out 5 when z is equal to 10, the loop will be broken out 6 when z is equal to 10, the loop will be broken out 7 when z is equal to 10, the loop will be broken out 8 when z is equal to 10, the loop will be broken out 9 when z is equal to 10, the loop will be broken out 1971940899 |
STM32F407VGT6 开发板Beak at address "0x0" with no debug information our outside
BootLoader 与 DFU 模式的区别
调度器原子变量相关问题
运行到 WRITE_REG (FLASH->OPTKEYR, FLASH_OPTKEY1)跳转 HardFaultHandler
STM32F417IG 单端外部时钟旁路HSE Bypass问题
STM32L4A6 SDMMC 无法使用 1.8V IO 驱动 microSD 卡
STM32L4P5xx 系统内 Bootloader:RAM3 能否用作栈指针内存?
在 STM32CubeIDE 中生成 ioc 配置文件
CAN 总线多节点环境下进行固件升级
在 Bootloader 运行期间保持 GPIO 引脚电平状态不变
微信公众号
手机版
因为z==10,直接break了这个for循环,而z的生命周期只在这个for循环内,break后就销毁了,出现什么值都是未知的
[md]为啥z=10就break了
你的z在for循环中定义的,退出以后当然要归还堆栈,编译器会将z占用的这块栈内存标记为“已释放”或“可复用”,然后别的代码可能会写入数据。好点儿的编译器编译的时候就应该抱怨,甚至报错。
if(z==10) { break; }
这句不是你的代码里的吗?为啥会不知道自己的代码里有break
[md]知道什么意思了,解决了