我在用非标准方式在C中对结构进行类型定义时遇到问题。
我正在编写自己的内核。
struct Time {
int sec;
int min;
int hour;
int monthDay;
int month;
// Year count from 1900
int year;
// Week day <0; 6>; 0 - sunday...6 - saturday
int weekDay;
// Year day is counted from 0
int yearDay;
// If > 0 then there is summer time, if 0 then there is standard time,
// if < 0 then there isn't info about time
int timeZone;
};
typedef struct Time struct tm; // Doesn't work :(((
我这里有编译错误。我想通过两种方式定义struct Time变量:
struct Time a;
struct tm b;
我想有能力在tm b;
之前编写结构,因为我想标记类型tm是结构而不是简单的原始类型。
您试图做的事情在很多方面都很奇怪。我看不到很好的用例,但是自从您问到以后,我将提供一个解决方案。但我会强烈阻止这样做。
#define tm Time
struct Time {
int sec;
};
struct Time a;
struct tm b;
不可能用常规的typedef解决。