VSCode gives "incomplete type" messages (about timespec) I can't repeat using GCC command--how to solve this?

106 views Asked by At

Win64, VSCode set to use GCC to compile .C file.

I'm not able to get any similar warning from GCC on the command line, despite trying many options, and the code compiles and runs fine. Is intellisense going OTT?

The first error is defining tim, a timespec for nanosleep() in time.h and the only quick hint in VSCode is "disable error squiggles" :-)

(I also get errors on the code setting members of the stucture. "incomplete class type "struct timespec" is not allowed")

VSCode lists first problem as "incomplete type is not allowed" and a right-click lets me copy:-

[{
    "resource": "/C:/Users/Roopy/source/c/temp/temptemp.c",
    "owner": "C/C++: IntelliSense",
    "code": "70",
    "severity": 8,
    "message": "incomplete type is not allowed",
    "source": "C/C++",
    "startLineNumber": 5,
    "startColumn": 21,
    "endLineNumber": 5,
    "endColumn": 24
}]

example code:- #include <stdio.h> #include <time.h> /* for timespec, nanosleep() */

int main(int argc, char *argv[]) {
    struct timespec tim = {3,500000000L};
    
    tim.tv_sec =  2;
    tim.tv_nsec = 500000000L; /* 0.5 sec */
    
    puts("Starting nanosleep()...");
    fflush(stdin);
    if (nanosleep(&tim,&tim) < 0 ) {
      puts("nanosleep() failed.");
      return -1;
    }
    puts("Stopping.");
    return(0);
}
0

There are 0 answers