c++ - 如何尝试捕获诸如“#include”之类的预处理器指令
问题描述
有没有一种方法可以尝试捕获#include 指令,因为#include 是处理器指令,并且try catch 方法在编译期间完成,它不会起作用有什么解决方法吗?我需要检查是否可以包含一个文件,否则包含另一个文件。
解决方案
__has_include 函数以及使用 #if 和 #elif 可以做到这一点。
#if defined __has_include
# if __has_include (<stdatomic.h>)
# include <stdatomic.h>
# endif
#endif
来源:https ://gcc.gnu.org/onlinedocs/cpp/_005f_005fhas_005finclude.html
推荐阅读
- microservices - 我如何通过即时一致性满足跨微服务的业务需求?
- service - 使用 Windows 服务的蓝牙自定义配对
- c++ - 如何在 wxwidgets 中将 AppendCheckItem 默认设置为“检查”?
- node.js - 将 AWS SSL 证书安装到主服务器
- java - Arrays Left Rotation { 小程序员与时间复杂性的斗争}
- jquery - 如何在 Jquery 脚本中编写动态 URL
- swift - 隐藏标签中的文本时尝试调整 UIView 的大小
- android - 从 Firebase 动态链接获取查询参数
- laravel - 创建自己的 laravel 包
- javascript - next.js:是否可以只为 google bot 和其他爬虫做 SSR,而不是为用户做 SSR?