I have a requirement to have and embedded copyright string in this C project. I've tried various things with pragmas, but the string always gets optimized out.
Any wisdom on this topic?
BTR Controls, Inc.
Simple. Just make it const
const char string = “value” ;
I thought so too, but that did not do it. The data segment was shown as dropped in the map file. This was verified by dumping the binary with "xxd" and examining the text representation of the binary.
What I finally did, and which did work, was to append it to a table that was referenced in the code and which was not eliminated by the linker. But there must be a good way to do this other than that? Yes nothing refers to it, but there should be a good way to indicate not to optimize it.
Well, I expected it to be used!
if you want to stop the linker eliminating an unused data, use
__attribute__((used)) const string = “value”;
Retrieving data ...