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.

1 Answer 1

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); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.