gpt4 book ai didi

c - time_t st_mtime 行的语法错误?

转载 作者:太空狗 更新时间:2023-10-29 15:30:16 24 4
gpt4 key购买 nike

为什么这个程序在 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;
}

这是我尝试构建它时得到的结果:

$ 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

检查预处理器输出:

$  gcc -E test1.c > test1.d  

第 10 行显示为:

time_t st_mtim.tv_sec; 

仅当我包含“sys/stat.h”和“time.h”文件时才会出现错误。

最佳答案

如果你grep /usr/include for st_mtime,你会发现以下内容:

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

所以问题源于你使用了变量名st_mtime

关于c - time_t st_mtime 行的语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8713876/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com