Syntax error for string time_t st_mtime?

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".

+4
source share
1 answer

If you grep /usr/include for st_mtime , you will find the following:

 $ grep -r st_mtime /usr/include | grep define /usr/include/x86_64-linux-gnu/bits/stat.h:# define st_mtime st_mtim.tv_sec 

Thus, the problem is related to using the variable name st_mtime .

+5
source

Source: https://habr.com/ru/post/1389089/


All Articles