【发布时间】:2021-11-28 22:00:48
【问题描述】:
我在 herder 文件中初始化一个 extern 变量,然后在 (.c) 文件中使用它,但是当我编译我的代码时,我收到一条警告,上面写着:非静态变量没有先前的 extern 声明。 这是我的代码:
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]);
} */
我没有在主函数中使用那个变量。
【问题讨论】:
-
您的代码在
/* */中。这是一个评论,它被忽略了。删除/* */使其成为编译器。 -
@KamilCuk 我想这是在这里发帖的产物(有一个
"enter code here"、一个led.h和一个led.c混合在一起),但谁知道呢。 -
它来自发帖(/* */)
标签: c extern non-static