我有一种感觉,这可能与 C 语法有关,但我是从 C++ 开始我的编程生活的,所以我不确定。
基本上我见过这个:
struct tm t;
memset( &t, 0, sizeof(struct tm) );
我对这种语法有点困惑,因为通常我希望上面的内容看起来像这样:
tm t;
memset( &t, 0, sizeof(tm) );
两者有什么区别,为什么使用前者?
Update
结构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 兼容而保留的,在需要的地方。
与其他人所说的相反,不存在这样的事情自动类型定义,C 和 C++ 在如何管理用户定义类型的标识符方面也没有区别。唯一的区别在于查找。
您可以阅读更多内容here
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)