How to set a kernel entry point: error: pointers cannot be cast to integers during const eval
⚓ Rust 📅 2025-12-23 👤 surdeus 👁️ 3I'd like to create a struct (e.g. multiboot2) in a binary (i.e. a kernel) where the struct includes a pointer to the kernel entry point. But the compiler won't let me do it, giving me the pointers cannot be cast to integers during const eval error.
How can I achieve this?
Thanks
#![no_std]
#![no_main]
#[repr(C)]
struct Multiboot2 {
entry_point: u32,
}
static _multiboot_header: Multiboot2 = Multiboot2{
entry_point: main as usize as u32,
};
fn main() {
loop{};
}
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop{};
}
I'm aware this address isn't available until the linker runs. Maybe there is some incantation of extern that will let the compiler leave that unfilled until link time?
2 posts - 2 participants
🏷️ Rust_feed