[英]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.