c - 在 C 宏和转换方面需要帮助
问题描述
我有一个这样声明的操作码列表:
enum OpCode {
PUSH = 0x01,
POP = 0x02,
DUP = 0x03,
//...etc (the list is too long to copy-paste it here and it wouldn't make a lot of sense)
}
我想要的是“自动”(通过宏):
- 创建其字符串表示形式的数组,例如:
static const char *OpCodeStr[] = {"PUSH","POP","DUP",...};
- 使用不同的枚举值创建一个包含一些标签(用于调度)的数组,例如:
static void* dispatchTable[] = {&&PUSH_, &&POP_, &&DUP_, ...};
我相信使用 C 宏应该是可能的,但我仍然没有弄清楚如何。
有任何想法吗?
解决方案
推荐阅读
- go - 使用公共通道聚合来自多个 goroutine 的结果
- azure - 在两个 Azure 应用服务之间共享文件
- sql-server - 使用 Where 子句从一个表插入另一个表
- c# - 在 Unity 中获取 WASD 键以跟随相机旋转
- ios - SwiftUI 2 视图中的模型
- sql - 根据查询结果派生值并对数据进行分组
- java - 如何在 Spring Cloud Stream App 中反序列化 MessagePack
- python-3.x - 反转 MultiLabelBinarizer 以在列中创建列表
- c# - Linq:使用基于字符串的let语句对数据进行分组
- c# - 在静态方法中读取 cookie [ASP MVC]