【发布时间】:2011-10-11 16:55:20
【问题描述】:
我感觉这可能与 C 语法有关,但我的编程生涯是从 C++ 开始的,所以我不确定。
基本上我已经看到了:
struct tm t;
memset( &t, 0, sizeof(struct tm) );
我对这种语法有点困惑,因为通常我希望上面看起来像这样:
tm t;
memset( &t, 0, sizeof(tm) );
两者有什么区别,为什么用前者代替?
更新
我所指的结构tm在wchar.h中,定义如下:
struct tm {
int tm_sec; /* seconds after the minute - [0,59] */
int tm_min; /* minutes after the hour - [0,59] */
int tm_hour; /* hours since midnight - [0,23] */
int tm_mday; /* day of the month - [1,31] */
int tm_mon; /* months since January - [0,11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday - [0,6] */
int tm_yday; /* days since January 1 - [0,365] */
int tm_isdst; /* daylight savings time flag */
};
【问题讨论】:
-
struct tm来自标准 C 库,应该在 time.h 而不是 wchar.h 中找到 -
可能是,但它也在我平台上的 wchar.h 中(MSVC)。结构定义包含在
ifndef保护检查_TM_DEFINED中,但这与我原来的问题无关。 -
@Praetorian 事后看来只是重复。我最初的困惑来自不同的角度,这仍然是有价值的,并且是查找可以说是相同信息的有效且有用的替代方法。