Why does this program generate a syntax error when building in Ubuntu?
#include "stdio.h" #include "stdlib.h" #include "string.h" #include "time.h" #include "sys/types.h" #include "sys/stat.h" int main() { time_t st_mtime; printf("Hello\n"); return 0; }
Here is what I get when I try to build this:
$ gcc -o test1 test1.c test1.c: In function ?main?: test1.c:10: error: expected ?=?, ?,?, ?;?, ?asm? or ?__attribute__? before ?.? token test1.c:10: error: expected expression before ?.? token
Checking the preprocessor output:
$ gcc -E test1.c > test1.d
Shows line 10 as:
time_t st_mtim.tv_sec;
The error only occurs if I include the files "sys / stat.h" and "time.h".
source share