问题描述
关于宏的前一个帖子只是提醒我问这个问题。我用
避免使用宏并定义了一些常量,即:
const int BYTES_PER_TRACK = 10 * 256;
const int TRACK0_SS_OFFSET = 0;
const int TRACK0_SS_OFFSET = 10 * 256;
现在,问题是我的项目中有几个模块
引用这些常量,所以我必须在主头文件中使用''
BYTES_PER_TRACK'等中的'extern const',因此常量是
可用于其他模块。
我觉得在这样的情况下使用
宏的intead不是更好吗?或者不是?
感谢您提供的任何见解。
-
小睡一下,它可以挽救生命。 />
A previous thread about macros just reminded me to ask this. I have
avoided using macros and defined some constants i.e.:
const int BYTES_PER_TRACK = 10 * 256;
const int TRACK0_SS_OFFSET = 0;
const int TRACK0_SS_OFFSET = 10 * 256;
Now, the problem is that I have several modules in my project that
references these constants, so I have to use ''extern const in
BYTES_PER_TRACK'' etc., in the main header file so the constants are
available to other modules.
I feel that in a situation like that wouldn''t it be better to use
macros intead? Or not?
Thanks for any insights offered.
--
http://www.munted.org.uk
Take a nap, it saves lives.
推荐答案
按照上面指示的净指示。
-
答:因为它弄乱了人们通常阅读文字的顺序。
问:为什么这么糟糕?
A :热门发布。
问:usenet和电子邮件中最烦人的事情是什么?
Follow the net directions indicated above.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
考虑使用枚举:
enum {
BYTES_PER_TRACK = 10 * 256 ;
TRACK0_SS_OFFSET = 0;
// ...
};
祝福,
Roland Pibinger
Consider using enums:
enum {
BYTES_PER_TRACK = 10 * 256;
TRACK0_SS_OFFSET = 0;
// ...
};
Best wishes,
Roland Pibinger
错误,第二个应该是:
const int TRACK0_DS_OFFSET = 10 * 256;
-
小睡一下,它可以挽救生命。
Err, the second one should be:
const int TRACK0_DS_OFFSET = 10 * 256;
--
http://www.munted.org.uk
Take a nap, it saves lives.
这篇关于在C ++中使用宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!