我目前正在基于Contiki-NG和Cooja进行项目,并且正在尝试在网络模拟器Cooja的Sky Mote上实现C代码,但出现以下错误:

code.c:5:12: error: expected declaration specifiers or '...' before '&' token
code.c:5:17: error: expected declaration specifiers or '...' before numeric constant
../../Makefile.include:347:recipe for target 'code.c' failed
make: *** [code.o] Error 1
Process returned error code 2

我尝试在其他帖子上找到解决方案,但未找到任何答案。这是我的C程序如下:
#include "contiki.h"
#include <stdio.h>
#define PERIOD CLOCK_SECOND*2
static struct etimer et;   // Define the timer
etimer_set(&et, PERIOD);   // Set the timer

/* Definition of the processes (actually a protothread) */
   PROCESS(blink_LED, "blink_LED");

/* Load this process at boot */
   AUTOSTART_PROCESSES(&blink_LED);

/* The process */
   PROCESS_THREAD(blink_LED,ev,data)
   {
    /* Application starts */
       PROCESS_BEGIN();

    /* Main loop of the application */
       while(1){
                etimer_set(&et, PERIOD);
                PROCESS_WAIT_EVENT();
                printf("Event executed \n");

                if(etimer_expired(&et)){
                   printf("Timer RESET \n");
                   etimer_reset(&et);
                }

       }
    /* End of the process */
      PROCESS_END();
}

错误似乎来自此行:
etimer_set(&et, PERIOD);   // Set the timer

谢谢!

最佳答案

指令etimer_set(&et, PERIOD);调用函数etimer_set。编译器抱怨,因为它期望一个声明。您不能直接调用像您编写的指令一样的指令。例如,这是调用mainetimer_set函数的声明:

int main () {
  etimer_set(&et, PERIOD);
  return 0;*
}

关于c - Cooja-C中的预期声明说明符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50248614/

10-10 14:07