#include
typedef std::func
tion reqHandler;
reqHandler *l;
void setup() {
Serial.begin(115200);
Serial.printf("启动 realloc lambda 测试...n");
l=(reqHandler *) malloc(2*sizeof(reqHandler)); // set 0
Serial.printf("start assign 0 in set 0 l=%0xn",l);
l[0]=[](){ Serial.printf("lambda 0n"); };
l[1]=[](){ Serial.printf("lambda 1n"); };
l=(reqHandler *) realloc(l,4*sizeof(reqHandler)); // set 1
Serial.printf("start assign 2 in set 1 l=%0xn",l);
l[2]=[](){ Serial.printf("lambda 2n"); };
l[3]=[](){ Serial.printf("lambda 3n"); };
l=(reqHandler *) realloc(l,6*sizeof(reqHandler)); // set 2
Serial.printf("start assign 4 in set 2 l=%0xn",l);
l[4]=[](){ Serial.printf("lambda 4n"); }; // creates a crash
l[5]=[](){ Serial.printf("lambda 5n"); };
Serial.printf("... End realloc lambda test.n");
}
void loop() { }
...创建以下输出:
启动 realloc lambda 测试...
开始在集合 0 中分配 0 l=3fff086c
开始在集合 1 中分配 2 l=3fff08a4
在集合 2 中开始分配 4 l=3fff08a4
ets Jan 8 2013,rst cause:4, boot mode:(1,6)
WDT 复位
It seems, the realloc function is not working correct. The "cause: 4" (=Level1InterruptCause) seems to make no sense at the point of the code which creates the crash.
我正在使用 ardunio IDE 1.6.8 和 ESP8266 插件
https://github.com/esp8266/Arduino/rele ... -2.3.0.zip.我的硬件是普通的 ESP-01。
IDE参数:
板卡:通用ESP8266模块
闪光模式:QIO
闪光频率:40MHz
CPU频率:80MHz
闪光灯大小:1M (192k SPIFFS)