Ok wtf is happening here? I know this is supposed to be printing out the position of the var in memory, but some weird stuff happens when I use their reference directly.
edit: Ok so apparently addition of two pointers can’t happen in C… I can just cast them to ints then. But that doesn’t explain why the subtraction doesn’t cause a crash and then produces an incorrect value anyways. wtf gcc
extern uint32_t kernstart; // &kernstart = 0x100000 (1 MB, beginning of upper memory)
extern uint32_t kernend; // &kernend = 0x10E824
printf("0x%s\n", itoa_nbuf(&kernend + &kernstart, 16) // this crashes
printf("0x%s\n", itoa_nbuf(&kernend - &kernstart, 16) // this compiles but prints out an incorrect value
uint32_t kernel_start = &kernstart;
uint32_t kernel_end = &kernend;
printf("0x%s\n", itoa_nbuf(kernel_end + kernel_start, 16) // compiles, prints right value (just for testing, no real use)
printf("0x%s\n", itoa_nbuf(kernel_end - kernel_start, 16) // compiles, prints right value (size of kernel)