请参阅下面的代码。当IAR MSP430编译器中的优化设置为高时,我会遇到以下问题。当优化程度较低时,代码运行良好。
问题:如果(B)处的条件语句返回false,则执行语句(A)而不是语句(C)。
int16_t cpu_flash_read_setting (void * setting, const uint8_t offset, const uint8_t num_of_bytes) { int16_t returnable_status = PASS; uint16_t flash_copy_one_address = FLASH_INFO_SEG_C_ADDR + offset; uint16_t flash_copy_two_address = FLASH_INFO_SEG_D_ADDR + offset; if (0U == (num_of_bytes % sizeof(uint16_t))) { uint16_t *setting_copy_one = (uint16_t *) flash_copy_one_address; uint16_t *setting_copy_two = (uint16_t *) flash_copy_two_address; if (*setting_copy_one == *setting_copy_two) { setting = setting_copy_one; } else { (A) returnable_status = FAIL; } } else if (0U == (num_of_bytes % sizeof(uint8_t))) { uint8_t *setting_copy_one = (uint8_t *) flash_copy_one_address; uint8_t *setting_copy_two = (uint8_t *) flash_copy_two_address; (B) if (*setting_copy_one == *setting_copy_two) { setting = setting_copy_one; } else { (C) returnable_status = FAIL; } } else { /* No Action */ } return returnable_status; }