-2

I am initializing an extern variable in a herder file and then use it in (.c) file but when i compile my code i get an warning that says: no previous extern declaration for non-static variable. Here is my code:

enter code here
/*led.h
extern int iStep = +1;

static void SetLEDPort2Output(void);
void LEDPortIni(void);
void LEDSet(unsigned char Value);
void PB10IntIni(void);
void TIM3IntIni(void);
void EXTI15_10_IRQHandler(void);
void TIM3_IRQHandler(void); */
/*led.c
#include <stm32f10x.h>
#include "led.h"

int iStep;

#define CHECKBIT(Var, Nr) (Var & (1<<Nr))
#define CLR_PORTBIT(PORT, BIT) {PORT->BRR |= (1<<BIT);}
#define SET_PORTBIT(PORT, BIT) {PORT->BSRR |= (1<<BIT);}
#define COPY_PORTBIT(Var, Nr, PORT, BIT) {if(CHECKBIT(Var, Nr)) SET_PORTBIT(PORT, BIT)\
                                            else CLR_PORTBIT(PORT, BIT)}

typedef struct
{
    GPIO_TypeDef* aGPIO[7];
    unsigned int aPIN[7];
} PORT;
    
static PORT LEDPort = 
      {{GPIOA, GPIOA, GPIOA, GPIOA, GPIOA, GPIOA, GPIOA},
             {    0,     1,     2,     3,     4,     5,     6}};


void EXTI15_10_IRQHandler(void)
{
    if(GPIOB->IDR & (0x1<<10))
        iStep = +1;
    else
        iStep = -1;
    EXTI->PR |= (0x1<<10);
}
void TIM3_IRQHandler(void)
{
    const unsigned char out[] = {0x1, 0x3, 0x6, 0xC, 0x18, 0x30, 0x60, 0x40};
    static int i = 0;
    i = (i + iStep) & 7;
    LEDSet(out[i]);
} */

I am not using that variable in the main function.

Progman
  • 16,827
  • 6
  • 33
  • 48

1 Answers1

0

It seems that in led.h there is a

extern int iStep = +1;

While in led.c:

int iStep;

It should be the other way around:

// Declaration in 'led.h'
extern int iStep;

// Definition in `led.c`
int iStep = 1;
Bob__
  • 12,361
  • 3
  • 28
  • 42
  • @Mohamad Please note that the header seems to be lacking [include guards](https://stackoverflow.com/questions/27810115/what-exactly-do-c-include-guards-do) too. – Bob__ Oct 09 '21 at 11:32