[应用方案] 全局Const能否被另外C文件使用

[复制链接]
858|2
 楼主| match007 发表于 2022-6-12 13:37 | 显示全部楼层 |阅读模式
比如说,在main.c定义
const int global_const=1;
在led.c:
第一种情况:
int a=global_const;
..\HARDWARE\LED\led.c(4): error:  #20: identifier "global_const" is undefined


第二种情况:
int const global_const;
int a=global_const;

..\HARDWARE\LED\led.c(4): error:  #28: expression must have a constant value


第三种情况:
extern int const global_const;
int a=global_const;

..\HARDWARE\LED\led.c(4): error:  #28: expression must have a constant value



第四种情况:
int const global_const;

..\OBJ\LCD.axf: Error: L6200E: Symbol global_const multiply defined (by led.o and main.o).

mutable 发表于 2022-6-12 14:00 | 显示全部楼层
是没有extern导致不能引入外部变量吧?

你试试
littlelida 发表于 2022-6-12 20:39 | 显示全部楼层
加extern就可以吧?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

97

主题

607

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部