在我问的上一个问题中,我发现无论出于何种原因,我都必须使用枚举在以下源代码中定义我的值:
enum { key0_buffer = 0};
void process_tuple(Tuple *t)
{
//Get key
int key = t->key;
//Get integer value, if present
int value = t->value->int32;
//Decide what to do
switch(key) {
case key_0:
enum {key0_buffer = value};
break;
};
}
...
static WeatherAppDataPoint s_data_points[] =
{
{
...
.high = key0_buffer,
},
};
在此代码中,旨在在 Pebble Watch(云 pebble.com)上运行,值来自在手机上运行的单独 JS 应用程序,然后接收该值。但是,如此处所见,我想将该整数转换为枚举器(原因在这里:初始化元素不是常量?)。代码吐出以下错误:
../src/app_data.c:120:5: error: a label can only be part of a statement and a declaration is not a statement
../src/app_data.c:120:11: error: enumerator value for 'key0_buffer' is not an integer constant
../src/app_data.c:109:9: error: variable 'value' set but not used [-Werror=unused-but-set-variable]
如何将整数转换为枚举数?