How best can I programmatically apply `__attribute__ ((unused))` to these automatically generated objects?

In my makefile , I have the following target that "compiles" text / HTML resources into unsigned char arrays using xxd -i .

I conclude the result with an anonymous namespace and header protection for security with multiple inclusions within and between translation units.

 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 

The result, if I had only one such resource, looks like this (actual content changed):

 #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 

What would be the best way to programmatically apply GCC __attribute__ ((unused)) to these character arrays? I do not want GCC to warn about any resources that I ultimately do not use in any given TU, but I also do not want to completely disable the "unused variables" warnings.

+3
c ++ gcc makefile xxd
05 Oct '11 at 11:22
source share
1 answer

I think a quick sed should work, given that the output of xxd -i very correct:

 xxd -i $$i | sed -e 's/ =/ __attribute__((unused)) =/' >> ../templates.h 
+2
05 Oct '11 at 11:29
source share



All Articles