2014-11-25 77 views
-1

我不知道为什么会发生这种情况。我正在做一个任务,代码不知道怎么编译。错误:在访问结构体时取消引用指向不完整类型的指针

这是头文件

#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

+0

什么是 缓冲区的类型? – 2014-11-25 06:09:52

+0

@Jefffrey我认为他把这只作为问题标题。第一次定时器常见:-) – 2014-11-25 06:12:36

+0

@SouravGhosh谢谢。 – Shoe 2014-11-25 06:13:16

回答

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