sin*_*yma 2 c floating-point autoconf gcc autotools
我正在使用一些autoconf的东西,并且测试包括以下内容:
static int test_array [1 - 2 * !((((float)((int)((float)1.4))) == ((float)1.4)) >= 0)];
Run Code Online (Sandbox Code Playgroud)
这失败了:
错误:'test_array'的存储大小不是常量
但当我改为:
static int test_array [1 - 2 * !((((int)((int)((int)1.4))) == ((int)1.4)) >= 0)];
Run Code Online (Sandbox Code Playgroud)
它工作正常.
我对autotools使用的所有hack都不是很熟悉,但这两个看起来似乎在编译时应该可以确定值.
为什么第一个失败?
让我们看一下标准(6.6(6)):
整数常量表达式应具有整数类型,并且只能具有整数常量的操作数,枚举常量,字符常量,
sizeof结果为整数常量的_Alignof表达式,表达式以及作为强制转换的直接操作数的浮点常量.整数常量表达式中的转换运算符只能将算术类型转换为整数类型,除非作为sizeof或_Alignof运算符的操作数的一部分.
(强调我的).
您不能转换float为整数常量表达式(除了参数sizeof或者_Alignof),因此
1 - 2 * !((((float)((int)((float)1.4))) == ((float)1.4)) >= 0)
Run Code Online (Sandbox Code Playgroud)
不是整数常量表达式.
static数组的元素数必须是求值为正整数的整数常量表达式.
| 归档时间: |
|
| 查看次数: |
135 次 |
| 最近记录: |