我有一个测试应用程序的问题我正在修改以更好地熟悉Pebble App SDK和C.我试图让我的代码运行函数struct App {
items: Vec<Item>
}
impl App {
fn new() -> App {
App { items: Vec::new() }
}
fn register_item(&mut self, item: Item) {
self.items.push(item);
}
}
pub struct Item;
fn main() {
let mut app = App::new();
app.register_item(Item);
}
但是无论出于何种原因,C跳过代码并继续运行其他功能。在示例中预先编写的所有其他函数运行没有问题。
为什么C决定跳过此函数,如何防止它跳过此代码。
weather_app_data.c
inbox_received_callback(DictionaryIterator *iterator, void *context)
weather_app_data.h
...other functions listed
void inbox_received_callback(DictionaryIterator *iterator, void *context) {
// Store incoming information
strcpy(city, "test");
static char temperature_buffer[8];
static char conditions_buffer[32];
static char weather_layer_buffer[32];
// Read first item
Tuple *t = dict_read_first(iterator);
// For all items
while(t != NULL) {
// Which key was received?
switch(t->key) {
case KEY_0:
snprintf(temperature_buffer, sizeof(temperature_buffer), "%dC", (int)t->value->int32);
break;
case KEY_1:
snprintf(conditions_buffer, sizeof(conditions_buffer), "%s", t->value->cstring);
break;
default:
APP_LOG(APP_LOG_LEVEL_ERROR, "Key %d not recognized!", (int)t->key);
break;
}
// Look for next item
t = dict_read_next(iterator);
}
}
}
static WeatherAppDataPoint s_data_points[] = {
{
.city = city, //This value is left blank by C even though defined in function that isn't running
.description = "Light Rain.",
.icon = WEATHER_APP_ICON_LIGHT_RAIN,
.current = 68,
.high = 70,
.low = 60,
},
...other items
};
答案 0 :(得分:1)
你真的没有提供足够的代码来给出一定的答案,但根据你所展示的内容,我认为@Peter已经砸到了头上。
您不会显示任何调用inbox_received_callback
的代码。根据您的编译器优化标记,您至少可以看到两个不同的东西: