0

I am declaring a static function in a header file and initializing it in .C file but i get a warning that says:unused function.

header file:

static void SetLEDPort2Output(void);

.c file:

static void SetLEDPort2Output(void)
{
    for(int i = 0;i < 7;i++)
    {
        LEDPort.aGPIO[i]->CRL &= ~(0x0Fu<<(4*LEDPort.aPIN[i]));
        LEDPort.aGPIO[i]->CRL |= (0x01<<(4*LEDPort.aPIN[i]));
    }
}
void LEDPortIni(void)
{
    RCC->APB2ENR |= 0x1<<2;
    SetLEDPort2Output();
}

I do not know what am i missing here.

Leland
  • 2,019
  • 17
  • 28

1 Answers1

1

in C, static functions are defined per compilation unit: What does "static" mean in C?

This means that every file that includes your header is going to have its own copy of this function declaration (possibly without a definition, since you defined it in your .c file), and the compiler is likely warning you that some of these copies are not used.

If you don't have a particular reason for your SetLEDPort2Output function to be static, you can declare and define it normally:

void SetLEDPort2Output(void);
Florian Castellane
  • 1,197
  • 2
  • 14
  • 38