armink / EasyFlash

Lightweight IoT device information storage solution: KV/IAP/LOG. | 轻量级物联网设备信息存储方案:参数存储、在线升级及日志存储 ,全新一代版本请移步至 https://github.com/armink/FlashDB
MIT License
1.99k stars 760 forks source link

宏展开无法使用枚举变量 #118

Open AaronKonishi opened 3 years ago

AaronKonishi commented 3 years ago

https://github.com/armink/EasyFlash/blob/ef3556f2026f7af6be2408d2cd9b4c5726d98df4/easyflash/src/ef_env.c#L1074

此处的代码会宏展开ENV_STATUS_TABLE_SIZE 和DIRTY_STATUS_TABLE_SIZE,而他们会分别使用枚举变量:ENV_STATUS_NUM和SECTOR_DIRTY_STATUS_NUM。而枚举变量在宏展开时是没法使用的,一般编译器会自动把ENV_STATUS_NUM和SECTOR_DIRTY_STATUS_NUM设置为0,因此#if (ENV_STATUS_TABLE_SIZE >= DIRTY_STATUS_TABLE_SIZE)始终为真,从而导致: uint8_t status_table[ENV_STATUS_TABLE_SIZE];语句永久有效; uint8_t status_table[DIRTY_STATUS_TABLE_SIZE];语句无法有效。

armink commented 3 years ago

你好,方便提交一个 PR 吗?