简体   繁体   English

当我编译内核时,是什么导致这个奇怪的警告? 传递不兼容的指针类型,期望的struct *但得到struct *

[英]What's Causing This Strange Warning When I Compile My Kernel? Passing incompatible pointer type, expected struct * but got struct *

I'm hoping that someone might be able to explain this to me. 我希望有人能够向我解释这一点。 I'm writing my own OS, and getting into writing the memory manager. 我正在编写自己的操作系统,并开始编写内存管理器。 I keep getting a weird warning when I compile my kernel. 编译内核时,我一直收到一个奇怪的警告。 The warning is quite paradoxical to me. 这个警告对我来说是相当矛盾的。 The function is getting the type of parameter it expects, but complaining as if otherwise. 该函数正在获取它所期望的参数类型,但是抱怨就好了。 Everything runs fine, and I'm able to get the information I need to initialize my memory manager. 一切运行正常,我能够获得初始化内存管理器所需的信息。 Can you tell me what's causing this? 你能告诉我是什么原因引起的吗?

$HOME/opt/cross/bin/i686-elf-gcc -c -ffreestanding -O2 -Wall -Wextra -std=gnu99 -ggdb -isystem src/h -o build/kernel.co src/c/kernel.c $ HOME / opt / cross / bin / i686-elf-gcc -c -ffreestanding -O2 -Wall -Wextra -std = gnu99 -ggdb -isystem src / h -o build / kernel.co src / c / kernel.c

src/c/kernel.c: In function 'kernel_main': src/c/kernel.c:29:2: warning: passing argument 1 of 'memory_manager_initialize' from incompatible pointer type src / c / kernel.c:在函数'kernel_main'中:src / c / kernel.c:29:2:警告:从不兼容的指针类型传递'memory_manager_initialize'的参数1

memory_manager_initialize(mboot_ptr); memory_manager_initialize(mboot_ptr); // wtf does this cause a warning? // wtf会导致警告吗?

In file included from src/h/system.h:39:0, from src/h/multiboot.h:4, from src/c/kernel.c:1: 在src / h / system.h:39:0中包含的文件中,来自src / h / multiboot.h:4,来自src / c / kernel.c:1:

src/h/memory.h:35:6: note: expected 'struct multiboot *' but argument is of type 'struct multiboot *' src / h / memory.h:35:6:注意:预期'struct multiboot *'但参数类型为'struct multiboot *'

void memory_manager_initialize(struct multiboot *mboot_ptr); void memory_manager_initialize(struct multiboot * mboot_ptr);

Here's the code for my loader that GRUB calls. 这是GRUB调用的加载程序的代码。

# Declare constants used for the multiboot header
.set ALIGN,        1<<0
.set MEMINFO,    1<<1
.set MAGIC,        0x1BADB002
.set FLAGS,        ALIGN | MEMINFO
.set CHECKSUM,    -(MAGIC + FLAGS)

.global .multiboot
.extern code
.extern bss
.extern end

.section .multiboot
    #.align 4
    .long MAGIC
    .long FLAGS
    .long CHECKSUM
    .long .multiboot
    .long code
    .long bss
    .long end
    .long _start

.section .text
    .global _start
    .extern kernel_main
    .type _start, @function
    _start:
        push %esp
        push %ebx
        cli
        call kernel_main
        .hang:
            jmp .hang

.size _start, . - _start

Here's the code from my kernel where the warning is coming from. 这是我的内核中发出警告的代码。

int kernel_main(struct multiboot *mboot_ptr, u32int initial_stack)
{
    initial_esp = initial_stack;

    gdt_initialize();
    idt_initialize();
    memset((u8int *) &interrupt_handler, 0, sizeof(isr) * 256);

    enable_interrupts();
    timer_initialize(100);
    keyboard_initialize();
    keyboard_set_handler(kernel_keyboard_handler);
    vga_set_handler(kernel_vga_handler);
    memset((u8int *) terminal_buffer, 0, MAX_TERMINAL_BUFFER_SIZE); // clear the terminal buffer (initalize it to 0 when we start running)

    // i need to get the memory management going.
    memory_manager_initialize(mboot_ptr);    // wtf does this cause a warning?

And the function that's being called is defined as 并且被调用的函数被定义为

void memory_manager_initialize(struct multiboot *mboot_ptr)

Either your struct is defined as: 您的结构定义为:

typedef struct {
    /*  Stuff  */
} multiboot;

when it should be defined as: 什么时候应该定义为:

typedef struct multiboot {    //  Note difference in this line
    /*  Stuff  */
} multiboot;

or your function prototype for memory_manager_initialize() appears before the compiler sees your definition of struct multiboot . 或者在编译器看到struct multiboot的定义之前出现了memory_manager_initialize()函数原型。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的struct typedef有什么问题导致“将指针解引用为不完整的类型?” - What is wrong with my struct typedef causing “dereferencing pointer to incomplete type?” 当我想引用结构变量时,指针类型不兼容 - Incompatible pointer type when I want to refer to a struct variable C,指向结构中函数的指针,警告“从不兼容的指针类型赋值” - C, pointer to function in struct, warning “assignment from incompatible pointer type” 警告:不兼容的指针类型将“char *”传递给“FILE *”类型的参数(又名“struct __sFILE *”) - warning: incompatible pointer types passing 'char *' to parameter of type 'FILE *' (aka 'struct __sFILE *') 警告:从链表结构中不兼容的指针类型分配 - Warning: assignment from incompatible pointer type in linked list struct 警告:结构中的2d指针从不兼容的指针类型分配 - warning: assignment from incompatible pointer type by 2d pointers in the struct C当使用struct * = struct时,如何从不兼容的指针类型解析分配 - C how can i resolve assignment from incompatible pointer type when using struct* = struct 将指针传递给gets()时在结构中使用指针有什么问题? - What's wrong with using pointer in a struct when passing it to gets()? 为什么我会收到“警告:来自不兼容指针类型的分配”? 结构数组中的双链表 - Why am i getting “warning: assignment from incompatible pointer type”? Double linked list in a struct array 与typedef和struct不兼容的指针类型警告 - Incompatible pointer types warning with typedef and struct
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM