简体   繁体   English

非静态外部变量

[英]Non-Static Extern variable

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.我正在 herder 文件中初始化一个 extern 变量,然后在 (.c) 文件中使用它,但是当我编译我的代码时,我收到一条警告:没有先前的非静态变量的 extern 声明。 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.我没有在主 function 中使用该变量。

It seems that in led.h there is a好像在led.h中有一个

extern int iStep = +1;

While in led.c :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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM