Skip to main content
1 of 3

compiler optimizes out pointer to function when address is assigned manually

I need to call a function at address 0xDD2:

// foo.h
void foo(void) __at(0xDD2);

// foo.c
void foo(void)
{
    // some code
}

This code works:

void (*a)(void) = &foo;
a();

However, this one doesn't:

void (*a)(void) = (void (*)(void))(0x0DD2);
a();

The compiler (XC8) says: main.c:13:: warning: (759) expression generates no code and debugger passes these lines while debugging.

I need second one (call function just by its address). Why compiler optimizes it out? Is there any mistake in pointer assignment? Changing optimization level of compiler didn't help.