错误:访问struct时解除引用指向不完整类型的指针

时间:2014-11-25 06:08:34

标签: 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

错误是:

  

错误:访问struct

时解除引用指向不完整类型的指针

1 个答案:

答案 0 :(得分:1)

你需要改变

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