错误“在'if'之前的说明符中的预期声明”

时间:2017-01-16 05:10:33

标签: c kaa

这些错误意味着什么?在生成Kaa SDK并运行它之后,我正在关注指南,但我遇到了这些错误。

 /home/pi/labsdk-RP/client/c/src/kaa_demo.c: In function ‘main’:
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:145:5: error: parameter ‘ret’ is initialized
         int ret = target_initialize();
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:146:5: error: expected declaration specifiers before ‘if’
         if (ret < 0) {
         ^
    In file included from /home/pi/labsdk-RP/client/c/src/kaa_demo.c:20:0:
    /home/pi/labsdk-RP/client/c/targets/posix/target.h:34:31: error: expected declaration specifiers before ‘printf’
     #define demo_printf(msg, ...) printf((msg), ##__VA_ARGS__)
                                   ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:152:5: note: in expansion of macro ‘demo_printf’
         demo_printf("Data collection demo started\r\n");
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:157:5: error: parameter ‘kaa_client’ is initialized
         kaa_client_t *kaa_client = NULL;
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:158:5: error: parameter ‘error’ is initialized
         kaa_error_t error = kaa_client_create(&kaa_client, NULL);
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:160:5: error: expected declaration specifiers before ‘if’
         if (error) {
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:166:5: error: expected declaration specifiers before ‘sensor_context’
         sensor_context.kaa_client = kaa_client;
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:167:5: error: parameter ‘receiver’ is initialized
         kaa_configuration_root_receiver_t receiver = {
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:172:5: error: expected declaration specifiers before ‘error’
         error = kaa_configuration_manager_set_root_receiver(
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:176:5: error: expected declaration specifiers before ‘if’
         if (error) {
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:181:5: error: parameter ‘default_configuration’ is initialized
         const kaa_configuration_empty_data_t *default_configuration =
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:184:5: error: expected declaration specifiers before ‘sensor_context’
         sensor_context.sample_period = default_configuration->sample_period;
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:185:5: error: expected declaration specifiers before ‘sensor_context’
         sensor_context.last_upload_time = time(NULL);
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:187:5: error: parameter ‘log_upload_strategy_context’ is initialized
         void *log_upload_strategy_context = NULL;
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:188:5: error: expected declaration specifiers before ‘error’
         error = ext_log_upload_strategy_create(kaa_client_get_context(kaa_client),
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:191:5: error: expected declaration specifiers before ‘if’
         if (error) {
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:196:5: error: expected declaration specifiers before ‘error’
         error = ext_log_upload_strategy_set_threshold_count(log_upload_strategy_context,
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:199:5: error: expected declaration specifiers before ‘if’
         if (error) {
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:204:5: error: expected declaration specifiers before ‘error’
         error = kaa_logging_set_strategy(kaa_client_get_context(kaa_client)->log_collector,
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:207:5: error: expected declaration specifiers before ‘if’
         if (error) {
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:215:5: error: expected declaration specifiers before ‘error’
         error = kaa_client_start(kaa_client, temperature_update,
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:218:5: error: expected declaration specifiers before ‘if’
         if (error) {
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:226:5: error: expected declaration specifiers before ‘kaa_client_destroy’
         kaa_client_destroy(kaa_client);
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:228:5: error: expected declaration specifiers before ‘return’
         return EXIT_SUCCESS;
         ^
    /home/pi/labsdk-RP/client/c/src/kaa_demo.c:229:1: error: expected declaration specifiers before ‘}’ token

预期声明是什么意思?我应该做某种形式的宣言吗?原始的演示代码完美运行。下面是kaa_demo.c的代码:

1 个答案:

答案 0 :(得分:1)

kaa_demo.c中你有:

int main(void)
//{
    //{
        //float batt; float cel; float wt;

        //for (batt = 4.99 && cel = 3.99 && wt = 2.99; batt > 0 && cel > 0 && wt > 0; batt-- && cel-- && wt--){
            //  printf("%d\n",batt,cel,wt);
        //}
        //return 0;
    //}
//}


    /**
     * Initialise a board.
     */
    int ret = target_initialize();
    if (ret < 0) {

由于没有开括号,编译器认为您正在尝试使用K&R-style function parameter list。只需添加一个支撑:

int main(void)
{ //<----Notice the new brace
//{
    //{
        //float batt; float cel; float wt;

        //for (batt = 4.99 && cel = 3.99 && wt = 2.99; batt > 0 && cel > 0 && wt > 0; batt-- && cel-- && wt--){
            //  printf("%d\n",batt,cel,wt);
        //}
        //return 0;
    //}
//}


    /**
     * Initialise a board.
     */
    int ret = target_initialize();
    if (ret < 0) {

回答技术问题,

  

预期声明是什么意思?

编译器期望函数作用域的开头,即开始{或函数参数列表。然后第二次引用ret已经从它的角度声明,因此你不能再声明它。它期待着一个新的宣言。