c - 错误: dereferencing pointer to incomplete type when accessing struct

标签 c

我不确定为什么会发生这种情况。我正在做一项作业,但代码不知何故无法编译。

这是头文件

#include <stdint.h>

typedef struct
{
    uint8_t jump_code[3];   /* Ignore this */
    char oemname[8];        /* Might as well ignore this one too */
    uint8_t ssize[2];       /* Sector size in bytes */
    uint8_t csize;          /* Cluster size in sectors */
    uint8_t reserved[2];    /* Number of reserved sectors for boot sectors */
    uint8_t numfat;         /* Number of FATs */
    uint8_t numroot[2];     /* Number of Root directory entries */
    uint8_t sectors16[2];   /* number of sectors in the file system */
    uint8_t media[1];       /* Media descriptor type */
    uint8_t sectperfat16[2];/* Number of sectors per FAT */
    uint8_t sectpertrack[2];/* Number of sectors per track */
    uint8_t heads[2];       /* Number of heads */
    uint8_t prevsect[2];    /* Number of sectors before FS partition */
    uint8_t ignore[482];    /* Ignore these */
} boot_sect_t;

这是给出错误的部分:

struct boot_sect_t* boot = malloc(sizeof(boot_sect_t));
boot->ssize[0] = buffer[11]; //error here
boot->ssize[1] = buffer[12]; //error here

错误是:

error: dereferencing pointer to incomplete type when accessing struct

最佳答案

你需要改变

struct boot_sect_t* boot = malloc(sizeof(boot_sect_t));

boot_sect_t* boot = malloc(sizeof(boot_sect_t));

boot_sect_t 已经是 typedef。无需编写struct boot_sect_t

关于c - 错误: dereferencing pointer to incomplete type when accessing struct,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27119872/

相关文章:

c - 如何在 C 中将项目添加到 2D "ArrayList"并在其中搜索项目

c - C头文件的实现?

c - 在 Mac 上构建 HIDAPI 的问题

c++ - 有没有办法使用 visual studio 命令提示符进行调试?

c - 为什么我得到 : "error: assignment to expression with array type"

c - 如何编写段错误处理程序,以便不重新启动错误指令? (C 和 Linux)

c - 将结构体的 fwrite() 和 fread() 部分写入二进制文件

c++ - 我需要在 Windows 上同步对 HANDLE 的访问吗?

c - C中从文件读取到数组

c - 将结构字段传递给 C 中的函数