积极答复者
关于C++头文件中的一个结构体的定义

问题
-
struct _CRTIMP2_PURE _Num_base
{
// base for all types, with common defaults _STCONS(float_denorm_style, has_denorm, denorm_absent);
_STCONS(bool, has_denorm_loss, false);
_STCONS(bool, has_infinity, false);
_STCONS(bool, has_quiet_NaN, false);
_STCONS(bool, has_signaling_NaN, false);
_STCONS(bool, is_bounded, false);
_STCONS(bool, is_exact, false);
_STCONS(bool, is_iec559, false);
_STCONS(bool, is_integer, false);
_STCONS(bool, is_modulo, false);
_STCONS(bool, is_signed, false);
_STCONS(bool, is_specialized, false);
_STCONS(bool, tinyness_before, false);
_STCONS(bool, traps, false);
_STCONS(float_round_style, round_style, round_toward_zero);
_STCONS(int, digits, 0); _STCONS(int, digits10, 0);
#if _HAS_CPP0X _STCONS(int, max_digits10, 0);
#endif /* _HAS_CPP0X */ _STCONS(int, max_exponent, 0);
_STCONS(int, max_exponent10, 0);
_STCONS(int, min_exponent, 0);
_STCONS(int, min_exponent10, 0);
_STCONS(int, radix, 0);
};
以上为头文件limits中的一个结构体,在_Num_base之前是_CRTIMP2_PURE,而_CRTIMP2_PURE在yvals.h中#define _CRTIMP2_PURE _CRTIMP2,而_CRTIMP2在crtdefs.h中#define _CRTIMP2。这么说来上面结构体定义为struct _CRTIMP2 _Num_base{....}这样的定义实在搞不懂。
hooke
- 已编辑 lucy-liuModerator 2010年12月23日 2:19 make it more readable
答案
-
Hi steven,
>>crtdefs.h中#define _CRTIMP2
定义标识,标识有效范围为整个程序,即_CRTIMP2在整个程序中有效。
>>yvals.h中#define _CRTIMP2_PURE _CRTIMP2
字符替换,在本程序中所有的CRTIMP2_PURE 都替换成_CRTIMP2。
>>头文件limits中的一个结构体,在_Num_base之前是_CRTIMP2_PURE
定义_CRTIMP2_PURE 结构体,_Num_base是_CRTIMP2_PURE的一个实例。
>>这么说来上面结构体定义为struct _CRTIMP2 _Num_base{....}
如果include了yvals.h才是这样。
用#define _CRTIMP2_PURE _CRTIMP2 这样编写源程序时,所有的_CRTIMP2 都可由_CRTIMP2_PURE 代替,而对源程序作编译时,将先由预处理程序进行宏代换,即用_CRTIMP2 表达式去置换所有的宏名_CRTIMP2_PURE ,然后再进行编译。可以防止变量名重复。而且以后要改变_CRTIMP2_PURE 的值只要在#define _CRTIMP2_PURE _CRTIMP2 中变动就行了,不必把程序中所有_CRTIMP2_PURE都变动。
Define一般有三种用法:
第一种是定义标识,标识有效范围为整个程序,形如#define XXX,常与#if配合使用;
第二种是定义常数,如#define max 100,则max代表100;
第三种是定义"函数",如#define get_max(a, b) ((a)>(b)?(a):(b)) 则以后使用get_max(x,y)就可以得到x和y中较大的数(这种方法的确非常灵活,因为a和b可以是各种数据类型。)。
谢谢,
Lucy
Lucy Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 steven hooke 2010年12月24日 7:12
全部回复
-
Hi steven,
欢迎在Microsoft中文论坛发帖。
我修改了你帖子的格式,使它看起来更加舒服整洁。请不要介意。
谢谢,
Lucy
Lucy Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
Hi steven,
>>crtdefs.h中#define _CRTIMP2
定义标识,标识有效范围为整个程序,即_CRTIMP2在整个程序中有效。
>>yvals.h中#define _CRTIMP2_PURE _CRTIMP2
字符替换,在本程序中所有的CRTIMP2_PURE 都替换成_CRTIMP2。
>>头文件limits中的一个结构体,在_Num_base之前是_CRTIMP2_PURE
定义_CRTIMP2_PURE 结构体,_Num_base是_CRTIMP2_PURE的一个实例。
>>这么说来上面结构体定义为struct _CRTIMP2 _Num_base{....}
如果include了yvals.h才是这样。
用#define _CRTIMP2_PURE _CRTIMP2 这样编写源程序时,所有的_CRTIMP2 都可由_CRTIMP2_PURE 代替,而对源程序作编译时,将先由预处理程序进行宏代换,即用_CRTIMP2 表达式去置换所有的宏名_CRTIMP2_PURE ,然后再进行编译。可以防止变量名重复。而且以后要改变_CRTIMP2_PURE 的值只要在#define _CRTIMP2_PURE _CRTIMP2 中变动就行了,不必把程序中所有_CRTIMP2_PURE都变动。
Define一般有三种用法:
第一种是定义标识,标识有效范围为整个程序,形如#define XXX,常与#if配合使用;
第二种是定义常数,如#define max 100,则max代表100;
第三种是定义"函数",如#define get_max(a, b) ((a)>(b)?(a):(b)) 则以后使用get_max(x,y)就可以得到x和y中较大的数(这种方法的确非常灵活,因为a和b可以是各种数据类型。)。
谢谢,
Lucy
Lucy Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 steven hooke 2010年12月24日 7:12