尽管函数和结构是包含的头文件的成员,但 C 错误 : implicit declaration of function and storage size isn't known,

标签 c struct compiler-errors findfirst

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

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

struct ffblk ffblk;

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

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

storage size of ffblk isn't known

并且 findfirst() 函数返回:

warning: implicit declaration of function 'findfirst'[-Wimplicit-function-declaration]

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

最佳答案

如果你能完全避免的话,你真的、真的不应该使用像“dos.h”这样过时的 header 中的过时的 API。诚实!

尽管如此,如果您坚持...

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

  2. 记录在案here

  3. 您将看到此 API 的参数(同样 - 已过时)是 struct _finddata_t *fileinfo(而不是 struct ffblk) >).

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

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

关于尽管函数和结构是包含的头文件的成员,但 C 错误 : implicit declaration of function and storage size isn't known,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52249337/

相关文章:

c - 传递带有指针的二维数组并访问它会出现段错误

c - 在C中分配超过4GB的内存

c - pthread C 中的池线程

struct - 如何从字符串_and_创建迭代器并将其存储在结构中?

c++ - 在 vector 上找到第一对元素 (int) 并获得第二对 (struct)

c - 逻辑SSE内部函数之间有什么区别?

go - 将数据添加到结构中的 interface{}

c++ - 做std::pair a custom class的第二个参数

无法使用 C 语言将 'void*' 类型转换为 'double*' 或 'float*'

.net - ObservableCollection-无法实现,因为它没有匹配的返回类型