Variably modified array at file scope

后端 未结 2 1707
滥情空心
滥情空心 2021-01-12 13:35

What\'s wrong with the following code?

#define DELAY_CYCLES ((int)(0.1/0.001))
typedef struct {
    double state_history[N_X][DELAY_CYCLES];
    double foo;
} foo         


        
2条回答
  •  一整个雨季
    2021-01-12 13:55

    Even if it were an integer constant expression, (int)(0.1/0.001) could easily be either 99 or 100, since the values 0.1 and 0.001 do not exist in floating point. Determining which value IEEE 754 specifies would require checking both of 0.1 and 0.001 to see whether they're closer to their neighbors above or below, then actually doing the division of those neighbors - or just checking it on a conformant system. However this is one place where I would not want to rely on the implementation being conformant to get the right answer.

提交回复
热议问题