c - 从 C 中的字符串 var 执行 #if 条件的其他方法
问题描述
我正在尝试执行字符串 var“str”中给出的条件。
我试图将它放在宏定义中,但它不起作用。
不像,当条件像在“CONDITION_DEF”中一样直接定义时。
#define CONDITION_STR str
#define CONDITION_DEF defined A && defined B
#define A 1
#define B 1
int main(){
char *str = "defined A && defined B";
#if CONDITION_STR
printf("Condition from str: A and B are defined");
#endif
#if CONDITION_DEF
printf("Condition from define: A and B are defined");
#endif
}
输出:
"Condition from define: A and B are defined"
条件放置在字符串 var 中,以便我可以在运行时更改它。
还有其他方法可以从字符串变量执行#if 条件吗?
谢谢!
解决方案
这是不可能的,因为预处理是在 C 代码的实际编译之前完成的。预处理器对 C 和 C 变量一无所知。
推荐阅读
- python - sage 错误:没有名为 pygments.token 的模块
- javascript - 使用 puppeteer 测试 AWS 放大反应应用程序
- php - 带有 WHERE 或 BETWEEN 运算符的 SQL DATEDIFF
- google-cloud-platform - GCP Kubernetes Engine 我的第一个集群配置 - 当我更改区域时,集群创建失败
- haskell - 如何将 Either 转换为 MonadThrow
- python - 无法将 django 应用程序部署到 azure web 应用程序
- r - R - 在监督学习中使用虚拟变量和定量变量的神经网络包
- swift - 从 DB 更新 SwiftUI 视图
- kdb - 表列定义
- php - 防止 Web 会话攻击