I have a feeling this may be related to C syntax, but I started my programming life with C++ so I am not sure.
Basically I have seen this:
struct tm t;
memset( &t, 0, sizeof(struct tm) );
I am a bit confused with this syntax, as normally I would expect the above to instead look like this:
tm t;
memset( &t, 0, sizeof(tm) );
What is the difference between the two, and why is the former used instead?
Update
The structure tm that I am referring to is in wchar.h, and the definition is as follows:
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 */
};
The simple answer is that the
structkeyword there is present to restrict the lookup of the identifiertmto only user defined class types. It is probably left for compatibility with C, where it is required.Contrary to what others say, there is no such thing as auto-typedef, nor do C and C++ differ with respect to how the identifiers for user defined types are managed. The only difference is in lookup.
You can read more here