タイトルが示すように、私はこのコードを持っています:
typedef struct Book{
int id;
char title[256];
char summary[2048];
int numberOfAuthors;
struct Author *authors;
};
typedef struct Author{
char firstName[56];
char lastName[56];
};
typedef struct Books{
struct Book *arr;
int numberOfBooks;
};
gcc から次のエラーが表示されます。
bookstore.c:8:2: error: unknown type name ‘Author’
bookstore.c:9:1: warning: useless storage class specifier in empty declaration [enabled by default]
bookstore.c:15:1: warning: useless storage class specifier in empty declaration [enabled by default]
bookstore.c:21:2: error: unknown type name ‘Book’
bookstore.c:23:1: warning: useless storage class specifier in empty declaration [enabled by default]
次のように typedef を変更しても、警告もエラーも発生しません。
typedef struct{
char firstName[56];
char lastName[56];
} Author;
C プログラミング言語、第 2 版を検索し、数時間グーグルで検索した結果、最初の実装が機能しない理由がわかりません。