c - 这有什么问题吗? C

标签 c types header-files

我无法找到我的错误。这是 structurals.h 中的定义

typedef struct book {
  bank_account_t **accounts;
  transaction_t **transactions;
} book_t;

这里是在functions.c中,我包含 header 并尝试使用类型book_t

#include "structures.h"

void load_book(book_t *book) {

}

但是我收到这个错误

functions.c:10:16: error: unknown type name ‘book_t’
 void load_book(book_t *book) {
                ^

使用以下更多代码进行编辑:

在我的 main 文件中,我像这样排序我的 .h 文件

#include "structures.h"
#include "functions.h"

结构.h

#ifndef STRUCTURES_H
# define STRUCTURES_H


typedef struct bank_account {
  char *name;
  int amount;
} bank_account_t;

typedef struct transaction {
  char *name;
  int amount;
} transaction_t;

typedef struct book {
  bank_account_t **accounts;
  transaction_t **transactions;
} book_t;

#endif

function.c

#include <stdio.h>

#include "functions.h"
#include "structures.h"
#include "bank_account.h"
#include "transaction.h"

void load_book(book_t *book) {

}

void init_book() {

}

bank_account.h

#ifndef BANK_ACCOUNT_H
# define BANK_ACCOUNT_H

void init_new_bank();
void deinit_new_bank();

#endif

交易.h

#ifndef TRANSACTION_H
# define TRANSACTION_H

#endif

最佳答案

我认为问题一定出在functions.h中(原帖中没有包含它)。

functions.h

#ifndef FUNCTIONS_H
# define FUNCTIONS_H

/* [MarkU] required: include definition of book_t */
#include "structures.h"

void load_book(book_t *book);
void init_book();

#endif

如果没有#include Structures.h,就没有 boot_t 类型的定义。

使用 mingw32-gcc 4.7.2 构建并验证。省略#include,我看到了错误消息。

关于c - 这有什么问题吗? C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28779263/

相关文章:

c# - 适合一对 List <string> 对象的数据类型,作为一个容器来容纳这两个对象

types - 通配符模式覆盖多态变体的子类型约束

c - 前向声明抛出重定义错误

c - 如何在 macOS 上找到 C 头文件 errno.h 的位置?

c - 将指针地址保存到取消引用的指针/自己的 malloc 函数

c - Base 64解码在C中返回NULL

c - Visual Studio 2010 的替代 unistd.h 头文件

斯卡拉 2.10 : Dynamically instantiating case classes

c - union、.c 和 .h 文件中的 Typedef 嵌套结构

主线程上的条件变量 block