任何人都可以解釋爲什麼這個代碼不會編譯?從字符緩衝區中鑄造對象c
的main.c
typedef struct ext2_group_desc
{
unsigned long bg_block_bitmap; /* Blocks bitmap block */
unsigned long bg_inode_bitmap; /* Inodes bitmap block */
unsigned long bg_inode_table; /* Inodes table block */
unsigned int bg_free_blocks_count; /* Free blocks count */
unsigned int bg_free_inodes_count; /* Free inodes count */
unsigned int bg_used_dirs_count; /* Directories count */
unsigned int bg_pad;
unsigned long bg_reserved[3];
} group_desc;
int main() {
char buf[1024];
group_desc gd;
gd = (group_desc) buf;
return(0);
}
終端
$ bcc -ansi -c test.c
test.c:7.26: error: need scalar or pointer or void
test.c:7.26: error: assignment to/from struct/union of a different type
$
這應該做什麼?什麼是'ext2_group_desc'。你的代碼試圖告訴編譯器,*將字符數組與「ext2_group_desc」*相同,你認爲它是真的嗎? –
在我的實際代碼中,我讀了一個硬盤驅動器塊到這個'char buf'中,然後嘗試將它轉換爲組描述符結構(不是1024字節)。 –