如何使宏常量可以在C中全局访问? [英] How do I make macro constants globally accessible in C?

查看:58
本文介绍了如何使宏常量可以在C中全局访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.c文件和.h文件中定义了一些宏常量,如下所示:

I have some macro constants defined in a .c file and a .h file as follows:

#define LOCAL_L2_BASE_LV                                    (0x00800000UL)

.c文件和

#define FPGA_PLI_FEEDBACK_OFFSET_LV_FREQUENCY           (0x00007000UL)

在.h文件中

我想在其他头文件中使用这些常量.最好的方法是什么?我最初的想法是在要在其中使用常量的头文件中使用extern,但这有效吗?

I would like to use these constants in a different header file. What is the best way to do so? My initial idea was to use extern in the header file I want to use the constants in, but is this valid?

推荐答案

宏不能设为外部,它们不是变量.它们只是文本替换.为了使宏可用于其他标题,您需要包括定义宏的标题.

Macros can not be made extern, they are not variables. They are simply textual replacements. To make macros available to other header, you need to include the header defining the macro.

这篇关于如何使宏常量可以在C中全局访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆