【问题标题】:C errors: implicit declaration of function and storage size isn't known, despite the function and struct being members of an included header fileC 错误:不知道函数和存储大小的隐式声明,尽管函数和结构是包含的头文件的成员
【发布时间】:2023-03-10 11:09:02
【问题描述】:

我正在尝试制作一个简单地搜索其根文件夹中的任何文件的测试程序:

#include <stdio.h>
#include <dir.h>
#include <dos.h>

struct ffblk ffblk;

int main(){
    int result = findfirst("*.*", &ffblk,FA_ARCH);
    return 0;
}

但是当代码编译时,ffblkstruct 声明返回错误:

ffblk 的存储大小未知

findfirst() 函数返回:

警告:函数“findfirst”的隐式声明[-Wimplicit-function-declaration]

as seen in this image,即使 findfirstffblk 都是 dir.h 的成员,它已经包含在内。我正在使用Visual Studio 并使用GCC 进行编译。有人知道代码或头文件有什么问题吗?

【问题讨论】:

  • 问:您是否考虑过尝试警告告诉您的操作? &lt;dos.h&gt; is obsolete: consider using &lt;direct.h&gt; instead.&lt;dir.h&gt; is obsolete, consider using &lt;io.h&gt; instead.。建议:1)尝试替换“io.h”和“direct.h”,2)考虑使用struct ffblk f;
  • 是的。 findfirst() 仍然被认为是隐式声明的,并且结构的存储大小仍然未知,唯一改变的是名称。
  • 你想要_findfirst
  • 你想看看你是否可以使用本世纪的标题:(

标签: c struct compiler-errors findfirst


【解决方案1】:

如果可以避免的话,你真的,真的不应该使用过时的头文件中的过时 API,比如“dos.h”。诚实!

不过,如果你坚持...

  1. 正如 dbush 指出的,实际的(过时的!)API 是 _findfirst(不是 findfirst)。

  2. 记录在案here

  3. 你会看到这个(再次 - OBSOLETE)API 的参数是struct _finddata_t *fileinfo(不是struct ffblk)。

更改您的代码,一切都应该编译并运行。

更好的是,更改您的标头(更改为“io.h”和“dir.h”) - 原始代码应该可以编译并运行。

【讨论】:

  • 谢谢!我正在关注 2014 年帖子中的示例代码,该代码将自身复制到文件夹中的其他文件中,它同时使用了 dos.h 和 dir.h,以及 findfirst() 而不是 _findfirst()。对于像 C 这样古老的语言,我不认为标题会真的过时。
  • 平台(如“dos”)来来去去 - C 是永远的 :)
猜你喜欢
  • 1970-01-01
  • 2014-07-20
  • 1970-01-01
  • 1970-01-01
  • 2011-02-01
  • 1970-01-01
  • 2012-07-25
  • 1970-01-01
  • 2017-10-16
相关资源
最近更新 更多