我如何才能最好地将' __attribute__ ((unused)) '应用于这些自动生成的对象
How best can I programmatically apply `__attribute__ ((unused))` to these auto-generated objects?
在我的makefile
中,我有以下目标,它使用xxd -i
将文本/HTML资源"编译"成unsigned char
数组。
我将结果包装在一个匿名命名空间中,并在翻译单元内部和翻译单元之间使用头警卫来保证多包含安全。
templates.h:
@echo "#ifndef TEMPLATES_H" > templates.h
@echo "#define TEMPLATES_H" >> templates.h
@echo "// Auto-generated file! Do not modify!" >> templates.h
@echo "// NB: arrays are not null-terminated" >> templates.h
@echo "// (anonymous namespace used to force internal linkage)" >> templates.h
@echo "namespace {" >> templates.h
@echo "namespace templates {" >> templates.h
@cd templates;
for i in * ;
do
echo "Compiling $$i...";
xxd -i $$i >> ../templates.h;
done;
cd ..
@echo "}" >> templates.h
@echo "}" >> templates.h
@echo "#endif" >> templates.h
输出,如果我只有一个这样的资源,看起来像这样(实际内容编辑):
#ifndef TEMPLATES_H
#define TEMPLATES_H
// Auto-generated file! Do not modify!
// NB: arrays are not null-terminated
// (anonymous namespace used to force internal linkage)
namespace {
namespace templates {
unsigned char alert_email_finished_events_html[] = {
0x3c, 0x74, 0x61, 0x62, 0x6c, 0x0d, 0x0a
};
unsigned int alert_email_finished_events_html_len = 7;
}
}
#endif
以编程方式将GCC的__attribute__ ((unused))
应用于这些字符数组的最佳方法是什么?我不希望GCC警告我在任何给定的TU中最终没有使用的任何资源,但我也不想完全关闭"未使用的变量"警告。
我认为快速sed
应该工作,考虑到xxd -i
的输出是非常规则的:
xxd -i $$i | sed -e 's/ =/ __attribute__((unused)) =/' >> ../templates.h
相关文章:
- c++r值引用应用于函数指针
- 如何将记忆应用于此递归函数?
- 查找自动生成键并具有线性内存消耗的小型关联数组
- atoi() 在应用于大型命令行参数时会产生不正确的值
- 运算符'<'不能应用于类型 'string' 和 'string' 的操作数
- 应用于运算符而不是构造函数的显式关键字
- Qt:更新 QString 时自动生成的代码失败
- 我们可以将阈值应用于色彩空间模型的单个组件(如 RGB 和 LAB)吗?
- 应用于无符号类型的一元减号运算符
- C++函数,它将数组、谓词和运算符作为参数,并将运算符应用于满足谓词的数组元素
- 我可以将c ++清理器仅应用于程序的一部分而不是第三方库吗?
- 您可以将binary_search应用于具有自定义类型的矢量吗?
- 我可以说服自动生成的构造函数将我的 POD 类成员归零吗?
- 在 C++ 中自动生成方法
- 如何在OpenGL中将纹理应用于子网格
- 删除了所有自动生成的构造函数/运算符的类仍然可以从函数返回吗
- MSBuild 用于在生成时将 nuget 包应用于项目
- 自动将本地缩放应用于非全屏桌面连接(RDP 8.1及更高版本)
- 我如何才能最好地将' __attribute__ ((unused)) '应用于这些自动生成的对象
- 是否有一些类似于boost program_options的c++库/源代码,但用于*键盘快捷键自动生成帮助*