栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

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

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

//数据定义
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单次采样数据

改成如上后,编译通过

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/290364.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号