希望这是一个带有简单答案的简单问题。代码是用C编写的。
我正在将MPLAB IDE v1.60与XC8编译器一起使用,但无法识别“ clock_t”。我为器件PIC18F6520设置了MPLAB。
我尝试构建时收到的错误消息如下;

ClockTimer.c:16: error: undefined identifier "clock_t"
ClockTimer.c:16: error: expression syntax
ClockTimer.c:18: error: expression syntax
ClockTimer.c:19: error: undefined identifier "stop"
ClockTimer.c:19: error: undefined identifier "start"


代码如下;

#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <time.h>


int main()
{
    clock_t start = clock();
    // Execuatable code
    clock_t stop = clock();
    double elapsed = (double)(stop - start) * 1000.0 / CLOCKS_PER_SEC;
    printf("Time elapsed in ms: %f", elapsed);

}


有什么想法为什么不编译?
谢谢
标记

最佳答案

由于clock_t通常只是unsigned long的别名,请尝试使用

unsigned long start = clock();

07-24 09:37