keil5中多文件引用外部变量时候的static和extern

本文讨论了在C语言中使用`extern`和`static`关键字时遇到的语法错误,解释了错误原因在于先声明了`extern`后使用`static`。根据C语言标准,`extern`和`static`在同一作用域内不能同时用于同一标识符。修复此问题的方法是去掉`static`关键字,保持`extern`声明,以确保编译通过。
摘要由CSDN通过智能技术生成
//数据定义
extern static u16 AD_Vtemp[10];//装载10次ADC采样数据
extern static u16 AD_val;				//ADC单次采样数据

出现了这样的错误
MAIN.C(8): error C141: syntax error near ‘static’
MAIN.C(9): error C141: syntax error near ‘static’

下面是C语言标准:
If, within a translation unit, the same identifier appears with both internal and external linkage, the behavior is undefined.
而引用
For an identifier declared with the storage-class specifier extern in a scope in which a prior declaration of that identifier is visible, if the prior declaration specifies internal or external linkage, the linkage of the identifier at the later declaration is the same as the linkage specified at the prior declaration. If no prior declaration is visible, or if the prior declaration specifies no linkage, then the identifier has external linkage.
所以先出现 extern 后出现 static 是不行的,用extern外部声明即可

//数据定义
extern u16 AD_Vtemp[10];//装载10次ADC采样数据
extern u16 AD_val;				//ADC单次采样数据

改成如上后,编译通过

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

梦想当极客的小芦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值