c - 如何以非标准方式在 C 中键入定义结构
问题描述
我在以非标准方式在 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 解决这个问题是不可能的。
推荐阅读
- c# - 找不到引用的组件“System.Runtime”
- javascript - 了解 chrome 扩展中的函数范围
- ms-access - 创建每小时货币字段
- lstm - 在稳定的基线中使用 LSTM
- svelte - 用svelte中的js数据填充html表
- rust - 具有自有值的 Rust 块方法?
- javascript - Onclick to do show/hide 激活表单中的提交按钮
- netlogo - 在 Netlogo 中找到给定颜色之前到下一个补丁的距离
- r - chmod 777 对于托管在 AWS EC2 上的 Shiny 应用程序是否安全?
- javascript - 如何从图像文件夹文件中生成 URL 路径数组?使用 Javascript