2015-05-30 46 views
-1

我有一个测试应用程序的IM修改,以获得与卵石应用SDK和C.我试着让我的代码运行的功能inbox_received_callback(DictionaryIterator *iterator, void *context)但无论出于何种原因更好地了解一个问题,C跳过代码并继续运行其他功能。示例中预先写入的所有其他函数运行时没有问题。ç跳过功能在

为什么C决定跳过这个功能,如何防止它跳过此代码。

weather_app_data.c

...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 
}; 

weather_app_data.h

... other functions all listed 
void inbox_received_callback(DictionaryIterator *iterator, void *context); 
void inbox_dropped_callback(AppMessageResult reason, void *context); 
void outbox_failed_callback(DictionaryIterator *iterator, AppMessageResult reason, void *context); 
+0

所以你排除'Tuple * t = dict_read_first(iterator);'永远不会返回'NULL'?如果您没有调试器,请在该测试下面添加一行'if(t)printf(“t不是NULL \ n”);'。 – usr2564301

+5

调用'inbox_received_callback()'的代码在哪里?编写一个函数是不够的。其他一些功能需要调用它。 – Peter

+0

你有什么证据证明“* C跳过代码*”? –

回答

1

你真的没有提供足够的代码给予一定的答案,而是基于你做什么我展示认为@Peter已经击中了头部。

你不显示任何代码调用inbox_received_callback。根据你的编译器优化标志,你可以看到至少2个不同的东西:

  1. 你的功能在反汇编显示不出来,因为编译器优化了功能,因为没有人把它称为(通常-02发生,更大)。
  2. 你会看到你的函数的反汇编,但它仍然不执行任何操作,因为没有人把它叫做(用-O0看到)。
+0

@Peter做了它,在编辑更复杂的C代码时,这是我犯的一个原始错误。仔细查看之后,我忘记了将函数包含在main()函数中,所以没有任何提示。 – AgentSpyname